Skip to content

Commit

Permalink
Provide option for cleaner/prettier links by removing .html suffix (#42)
Browse files Browse the repository at this point in the history
Allow removing all `.html` suffixes from `{page}.html` by creating 
`{page}/index.html` through the `pretty_links: true` option in 
`config.yml`. Jekyll, Pelican and others have this feature and it can 
provide benefits when not all the source files are named `index.md`.

Co-authored-by: Leonardo Uieda <[email protected]>
  • Loading branch information
florian-wagner and leouieda authored Feb 22, 2023
1 parent ef86601 commit 9d5be67
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion nene/_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,18 @@ def build(config_file, console=None, style=""):
else:
console.print(" None found.")

def pretty_links(source, config):
"""Whether or not this page link should be prettyfied."""
activated = "pretty_links" in config and config["pretty_links"]
valid_page = not source.endswith("index.md") and source != "404.md"
return activated and valid_page

console.print(":dart: Determining destination path for pages:", style=style)
for page in site.values():
if "save_as" in page:
destination = Path(page["source"]).with_name(page["save_as"])
elif pretty_links(page["source"], config):
destination = Path(page["id"]) / "index.html"
else:
destination = Path(page["source"]).with_suffix(".html")
page["path"] = str(destination)
Expand Down Expand Up @@ -248,7 +256,7 @@ def export(site, files_to_copy, output_dir, console=None, style=""):
for page in pages_with_images:
console.print(f" {page['source']}")
for image_path, image in page["images"].items():
path = output_dir / Path(page["parent"]) / Path(image_path)
path = output_dir / Path(page["path"]).parent / Path(image_path)
console.print(f" ↳ {str(path)}")
path.parent.mkdir(parents=True, exist_ok=True)
path.write_bytes(image)
Expand Down

0 comments on commit 9d5be67

Please sign in to comment.