Skip to content

Commit 9d5be67

Browse files
Provide option for cleaner/prettier links by removing .html suffix (#42)
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]>
1 parent ef86601 commit 9d5be67

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

nene/_api.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,18 @@ def build(config_file, console=None, style=""):
112112
else:
113113
console.print(" None found.")
114114

115+
def pretty_links(source, config):
116+
"""Whether or not this page link should be prettyfied."""
117+
activated = "pretty_links" in config and config["pretty_links"]
118+
valid_page = not source.endswith("index.md") and source != "404.md"
119+
return activated and valid_page
120+
115121
console.print(":dart: Determining destination path for pages:", style=style)
116122
for page in site.values():
117123
if "save_as" in page:
118124
destination = Path(page["source"]).with_name(page["save_as"])
125+
elif pretty_links(page["source"], config):
126+
destination = Path(page["id"]) / "index.html"
119127
else:
120128
destination = Path(page["source"]).with_suffix(".html")
121129
page["path"] = str(destination)
@@ -248,7 +256,7 @@ def export(site, files_to_copy, output_dir, console=None, style=""):
248256
for page in pages_with_images:
249257
console.print(f" {page['source']}")
250258
for image_path, image in page["images"].items():
251-
path = output_dir / Path(page["parent"]) / Path(image_path)
259+
path = output_dir / Path(page["path"]).parent / Path(image_path)
252260
console.print(f" ↳ {str(path)}")
253261
path.parent.mkdir(parents=True, exist_ok=True)
254262
path.write_bytes(image)

0 commit comments

Comments
 (0)