diff --git a/Makefile b/Makefile index 4816b3da..74ea07f0 100644 --- a/Makefile +++ b/Makefile @@ -46,15 +46,19 @@ serve: .PHONY: post post: - poetry run python scripts/hugo_new.py post --branch + poetry run python scripts/hugo_new.py post .PHONY: event event: - poetry run python scripts/hugo_new.py event --branch + poetry run python scripts/hugo_new.py event .PHONY: project project: - poetry run python scripts/hugo_new.py project --branch + poetry run python scripts/hugo_new.py project + +.PHONY: press-release +press-release: + poetry run python scripts/hugo_new.py press-release --is_post_archetype # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Debug and Info diff --git a/content/press-release/_index.md b/content/press-release/_index.md new file mode 100644 index 00000000..cf961f21 --- /dev/null +++ b/content/press-release/_index.md @@ -0,0 +1,7 @@ +--- +banner: + image: heroes/news.jpg +cms_exclude: true +title: Press Releases +view: 2 +--- diff --git a/content/post/nicholas-nadeau-joins-grandir-sans-frontires-board-to-champion-accessible-stem-education/featured.jpg b/content/press-release/nicholas-nadeau-joins-grandir-sans-frontires-board-to-champion-accessible-stem-education/featured.jpg similarity index 100% rename from content/post/nicholas-nadeau-joins-grandir-sans-frontires-board-to-champion-accessible-stem-education/featured.jpg rename to content/press-release/nicholas-nadeau-joins-grandir-sans-frontires-board-to-champion-accessible-stem-education/featured.jpg diff --git a/content/post/nicholas-nadeau-joins-grandir-sans-frontires-board-to-champion-accessible-stem-education/index.md b/content/press-release/nicholas-nadeau-joins-grandir-sans-frontires-board-to-champion-accessible-stem-education/index.md similarity index 100% rename from content/post/nicholas-nadeau-joins-grandir-sans-frontires-board-to-champion-accessible-stem-education/index.md rename to content/press-release/nicholas-nadeau-joins-grandir-sans-frontires-board-to-champion-accessible-stem-education/index.md diff --git a/content/post/partnership-between-pivot-edge-and-nadeau-innovations/featured.jpg b/content/press-release/partnership-between-pivot-edge-and-nadeau-innovations/featured.jpg similarity index 100% rename from content/post/partnership-between-pivot-edge-and-nadeau-innovations/featured.jpg rename to content/press-release/partnership-between-pivot-edge-and-nadeau-innovations/featured.jpg diff --git a/content/post/partnership-between-pivot-edge-and-nadeau-innovations/index.md b/content/press-release/partnership-between-pivot-edge-and-nadeau-innovations/index.md similarity index 100% rename from content/post/partnership-between-pivot-edge-and-nadeau-innovations/index.md rename to content/press-release/partnership-between-pivot-edge-and-nadeau-innovations/index.md diff --git a/content/press.md b/content/press.md index 72a48d04..3a41ecc9 100644 --- a/content/press.md +++ b/content/press.md @@ -31,9 +31,10 @@ sections: exclude_future: false exclude_past: false featured_only: false - folders: "" + folders: + - press-release publication_type: "" - tag: press + tag: "" offset: 0 sort_ascending: false sort_by: Date diff --git a/scripts/hugo_new.py b/scripts/hugo_new.py index 6f02785a..5bb97b95 100644 --- a/scripts/hugo_new.py +++ b/scripts/hugo_new.py @@ -4,92 +4,59 @@ from string import ascii_lowercase, digits, whitespace import fire -import nbformat as nbf def sanitize_fname(s: str): - valid = ascii_lowercase + digits + whitespace + # lowercase, remove invalid chars, remove whitespace, + # replace whitespace with - + valid_chars = ascii_lowercase + digits + whitespace s = s.lower() - s = filter(lambda x: x in valid, s) + s = filter(lambda x: x in valid_chars, s) s = "".join(s) s = s.split() s = "-".join(s) return s -def get_title(): +def new(kind: str, is_post_archetype: bool = False): + # get title title = input(">>> Note title: ") logging.info(f"Title: {title}") - return title - - -def new(kind: str, notebook: bool = False, branch: bool = False): - # get title - title = get_title() slug = sanitize_fname(title) + logging.info(f"Slug: {slug}") # set path hugo_path = f"{kind}/{slug}" index_path = "content" / Path(hugo_path) / "index.md" - # create md document - cmd = ["hugo", "new", hugo_path] - logging.info(f"Hugo command: {' '.join(cmd)}") - subprocess.run(cmd) - - # create notebook if needed - if notebook: - create_notebook(path=index_path) + extra_args = [] + if is_post_archetype: + logging.info("Using post archetype") + extra_args.extend(["--kind", "post"]) + logging.info(f"Extra args: {extra_args}") - # create branch if needed - if branch: + # define commands + commands = [ + # create md document + ["hugo", "new", hugo_path] + extra_args, # checkout master - cmd = ["git", "checkout", "master"] - logging.info(f"Git command: {' '.join(cmd)}") - subprocess.run(cmd) - + ["git", "checkout", "master"], # create branch - cmd = ["git", "checkout", "-b", slug] - logging.info(f"Git command: {' '.join(cmd)}") - subprocess.run(cmd) - + ["git", "checkout", "-b", slug], # push branch - cmd = ["git", "push", "-u", "origin", slug] - logging.info(f"Git command: {' '.join(cmd)}") - subprocess.run(cmd) - + ["git", "push", "-u", "origin", slug], # commit document to branch - cmd = ["git", "add", str(index_path)] - logging.info(f"Git command: {' '.join(cmd)}") - subprocess.run(cmd) - - cmd = ["git", "commit", "-m", f"feat: added {kind}"] - logging.info(f"Git command: {' '.join(cmd)}") - subprocess.run(cmd) - + ["git", "add", str(index_path)], + ["git", "commit", "-m", f"feat: added {kind}"], # use gh cli to open pr with title and empty body - cmd = ["gh", "pr", "create", "--title", f'"feat: {title}"', "--body", '""'] - logging.info(f"GitHub command: {' '.join(cmd)}") - subprocess.run(cmd) - - # open document - cmd = ["code", str(index_path.parent)] - logging.info(f"VSCode command: {' '.join(cmd)}") - subprocess.run(cmd) - + ["gh", "pr", "create", "--title", f'"feat: {title}"', "--body", '""'], + # open document + ["code", str(index_path.parent)], + ] -def create_notebook(path: Path): - # get metadata and text - with open(path) as f: - metadata = f.read() - text = "\n" - - # write notebook content - nb = nbf.v4.new_notebook() - nb["cells"] = [nbf.v4.new_raw_cell(metadata), nbf.v4.new_markdown_cell(text)] - path = path.with_suffix(".ipynb") - logging.info(f"Writing notebook: {path}") - nbf.write(nb, path) + for cmd in commands: + logging.info(f"Running command: {' '.join(cmd)}") + subprocess.run(cmd) if __name__ == "__main__":