Skip to content

Commit b7692af

Browse files
authored
Allow pages to set destination using "save_as" (#37)
If a page sets the attribute "save_as" it will be used to set the destination file name. The folder can't be changed. Enables the creation of non-html files, like rss feeds, sitemaps, and others.
1 parent e892d92 commit b7692af

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

nene/_api.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,15 @@ def build(config_file, console=None, style=""):
112112
else:
113113
console.print(" None found.")
114114

115+
console.print(":dart: Determining destination path for pages:", style=style)
116+
for page in site.values():
117+
if "save_as" in page:
118+
destination = Path(page["source"]).with_name(page["save_as"])
119+
else:
120+
destination = Path(page["source"]).with_suffix(".html")
121+
page["path"] = str(destination)
122+
console.print(f" {page['id']}{page['path']}")
123+
115124
def get_parent(item):
116125
"""Return the name of the parent of a page for the groupby."""
117126
page = item[1]
@@ -173,8 +182,9 @@ def render(site, config, build, console=None, style=""):
173182

174183
console.print(":art: Converting Markdown content to HTML:", style=style)
175184
for page in site.values():
176-
console.print(f" {page['source']}")
177-
page["body"] = markdown_to_html(page)
185+
if "markdown" in page:
186+
console.print(f" {page['source']}")
187+
page["body"] = markdown_to_html(page)
178188

179189
console.print(":art: Rendering templates for final outputs:", style=style)
180190
for page in site.values():

nene/parsing.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ def load_markdown(path):
147147
"id": identifier,
148148
"type": "markdown",
149149
"parent": str(path.parent),
150-
"path": str(path.with_suffix(".html")),
151150
"source": str(path),
152151
}
153152
text = path.read_text(encoding="utf-8").strip()
@@ -178,7 +177,6 @@ def load_jupyter_notebook(path):
178177
"id": identifier,
179178
"type": "ipynb",
180179
"parent": str(path.parent),
181-
"path": str(path.with_suffix(".html")),
182180
"source": str(path),
183181
}
184182
notebook = nbformat.reads(path.read_text(encoding="utf-8"), as_version=4)

0 commit comments

Comments
 (0)