Commit e4612f49 authored by berumuron's avatar berumuron
Browse files

add: Allow to change the blog slug

parent 5e73a2c1
...@@ -176,7 +176,8 @@ template has access to a `ARTICLES` variable: ...@@ -176,7 +176,8 @@ template has access to a `ARTICLES` variable:
</html> </html>
``` ```
This will generate a `site/blog.html` page. This will generate a `site/blog.html` page. You can override the slug by
setting the `blog_slug` configuration variable (more on that later).
`Article` model has several public methods: `Article` model has several public methods:
...@@ -223,8 +224,10 @@ timezone: Europe/Paris ...@@ -223,8 +224,10 @@ timezone: Europe/Paris
``` ```
You can declare as many variables as you want, they all will be accessible in You can declare as many variables as you want, they all will be accessible in
the article template, uppercased and prepended by `SITE_`. `url` can be set to the article template, uppercased and prepended by `SITE_`. You can set a
`filesystem` for development (it will generate paths to the output directory). `blog_slug` (e.g. `index`) to change where the main blog page will be
generated. `url` can be set to `filesystem` for development (it will generate
paths to the output directory).
If you want to use a different configuration in development, you can specify If you want to use a different configuration in development, you can specify
different options under a `development` section: different options under a `development` section:
......
...@@ -14,21 +14,6 @@ from boop.feed import Feed ...@@ -14,21 +14,6 @@ from boop.feed import Feed
locale.setlocale(locale.LC_ALL, "") locale.setlocale(locale.LC_ALL, "")
class ProgramError(Exception):
"""Exception raised during the program execution.
Examples:
>>> try:
... raise ProgramError("Oops")
... except ProgramError as e:
... print(e.args[0])
Oops
"""
pass
def main(environment): def main(environment):
# Make sure ./_site folder is empty # Make sure ./_site folder is empty
output_path = os.path.join(os.curdir, "_site") output_path = os.path.join(os.curdir, "_site")
...@@ -46,13 +31,11 @@ def main(environment): ...@@ -46,13 +31,11 @@ def main(environment):
# Check that index file exists # Check that index file exists
index_filepath = os.path.join(os.curdir, "index.html") index_filepath = os.path.join(os.curdir, "index.html")
if not os.path.exists(index_filepath): if os.path.exists(index_filepath):
raise ProgramError("./index.html file does not exist") index_page = utils.build_page_from_filepath(
index_filepath, configuration, basename=os.curdir
index_page = utils.build_page_from_filepath( )
index_filepath, configuration, basename=os.curdir pages.append(index_page)
)
pages.append(index_page)
# Check that pages directory exists and load Pages from it # Check that pages directory exists and load Pages from it
pages_path = os.path.join(os.curdir, "pages") pages_path = os.path.join(os.curdir, "pages")
...@@ -143,8 +126,5 @@ def main(environment): ...@@ -143,8 +126,5 @@ def main(environment):
if __name__ == "__main__": if __name__ == "__main__":
environment = environment.load_from_argv(sys.argv) environment = environment.load_from_argv(sys.argv)
try: main(environment)
main(environment) print("Boop!")
print("Boop!")
except ProgramError as e:
print(e.args[0], file=sys.stderr)
...@@ -10,6 +10,7 @@ def load(configuration_path, environment, output_path): ...@@ -10,6 +10,7 @@ def load(configuration_path, environment, output_path):
"SITE_URL": "filesystem", "SITE_URL": "filesystem",
"SITE_TITLE": "A website", "SITE_TITLE": "A website",
"SITE_TIMEZONE": "UTC", "SITE_TIMEZONE": "UTC",
"SITE_BLOG_SLUG": "blog",
} }
if os.path.exists(configuration_path): if os.path.exists(configuration_path):
......
...@@ -52,7 +52,9 @@ def build_blog_page(articles, series, configuration): ...@@ -52,7 +52,9 @@ def build_blog_page(articles, series, configuration):
articles.sort(key=lambda article: article.date(), reverse=True) articles.sort(key=lambda article: article.date(), reverse=True)
series.sort(key=lambda serie: serie.title(), reverse=False) series.sort(key=lambda serie: serie.title(), reverse=False)
blog_page = Page("blog", "", configuration=configuration) slug = configuration["SITE_BLOG_SLUG"]
blog_page = Page(slug, "", configuration=configuration)
blog_page.meta["PAGE_TEMPLATE"] = "blog" blog_page.meta["PAGE_TEMPLATE"] = "blog"
blog_page.meta["ARTICLES"] = articles blog_page.meta["ARTICLES"] = articles
blog_page.meta["ARTICLES_BY_YEAR"] = itertools.groupby( blog_page.meta["ARTICLES_BY_YEAR"] = itertools.groupby(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment