diff --git a/ablog/__init__.py b/ablog/__init__.py index 9252bbf7..d936f042 100755 --- a/ablog/__init__.py +++ b/ablog/__init__.py @@ -6,6 +6,9 @@ from glob import glob from pathlib import PurePath +from sphinx.builders.html import StandaloneHTMLBuilder +from sphinx.jinja2glue import BuiltinTemplateLoader, SphinxFileSystemLoader + from .blog import CONFIG, Blog from .post import ( CheckFrontMatter, @@ -22,12 +25,23 @@ ) from .version import version as __version__ +PKGDIR = os.path.abspath(os.path.dirname(__file__)) + + __all__ = ["setup"] +def get_html_templates_path(): + """ + Return path to ABlog templates folder. + """ + pkgdir = os.path.abspath(os.path.dirname(__file__)) + return os.path.join(pkgdir, "templates") + + def anchor(post): """ - Return anchor string for posts that arepage sections. + Return anchor string for posts that are page sections. """ if post.section: return "#" + post.section @@ -59,6 +73,55 @@ def html_page_context(app, pagename, templatename, context, doctree): context["feed_title"] = blog.blog_title +def config_inited(app, config): + # Automatically identify any blog posts if a pattern is specified in the config + if isinstance(config.blog_post_pattern, str): + config.blog_post_pattern = [config.blog_post_pattern] + matched_patterns = [] + for pattern in config.blog_post_pattern: + pattern = os.path.join(app.srcdir, pattern) + # make sure that blog post paths have forward slashes even on windows + matched_patterns.extend( + PurePath(ii).relative_to(app.srcdir).with_suffix("").as_posix() + for ii in glob(pattern, recursive=True) + ) + app.config.matched_blog_posts = matched_patterns + + +def builder_inited(app): + if not isinstance(app.builder, StandaloneHTMLBuilder) or app.config.skip_injecting_base_ablog_templates: + return + if not isinstance(app.builder.templates, BuiltinTemplateLoader): + raise Exception( + "Ablog does not know how to inject templates into with custom " + "template bridges. You can use `ablog.get_html_templates_path()` to " + "get the path to add in your custom template bridge and set " + "`skip_injecting_base_ablog_templates = False` in your " + "`conf.py` file." + ) + if get_html_templates_path() in app.config.templates_path: + raise Exception( + "Found the path from `ablog.get_html_templates_path()` in the " + "`templates_path` variable from `conf.py`. Doing so interferes " + "with Ablog's ability to stay compatible with Sphinx themes that " + "support it out of the box. Please remove `get_html_templates_path` " + "from `templates_path` in your `conf.py` to resolve this." + ) + theme = app.builder.theme + loaders = app.builder.templates.loaders + templatepathlen = app.builder.templates.templatepathlen + if theme.get_config("ablog", "inject_templates_after_theme", False): + # Inject *after* the user templates and the theme templates, + # allowing themes to override the templates provided by this + # extension while those templates still serve as a fallback. + loaders.append(SphinxFileSystemLoader(get_html_templates_path())) + else: + # Inject *after* the user templates and *before* the theme + # templates. This enables ablog to provide support for themes + # that don't support it out-of-the-box, like alabaster. + loaders.insert(templatepathlen, SphinxFileSystemLoader(get_html_templates_path())) + + def setup(app): """ Setup ABlog extension. @@ -68,6 +131,7 @@ def setup(app): app.add_directive("post", PostDirective) app.add_directive("postlist", PostListDirective) app.connect("config-inited", config_inited) + app.connect("builder-inited", builder_inited) app.connect("doctree-read", process_posts) app.connect("env-purge-doc", purge_posts) app.connect("doctree-resolved", process_postlist) @@ -86,27 +150,3 @@ def setup(app): locale_dir = os.path.join(pkgdir, "locales") app.config.locale_dirs.append(locale_dir) return {"version": __version__} # identifies the version of our extension - - -def config_inited(app, config): - app.config.templates_path.append(get_html_templates_path()) - # Automatically identify any blog posts if a pattern is specified in the config - if isinstance(config.blog_post_pattern, str): - config.blog_post_pattern = [config.blog_post_pattern] - matched_patterns = [] - for pattern in config.blog_post_pattern: - pattern = os.path.join(app.srcdir, pattern) - # make sure that blog post paths have forward slashes even on windows - matched_patterns.extend( - PurePath(ii).relative_to(app.srcdir).with_suffix("").as_posix() - for ii in glob(pattern, recursive=True) - ) - app.config.matched_blog_posts = matched_patterns - - -def get_html_templates_path(): - """ - Return path to ABlog templates folder. - """ - pkgdir = os.path.abspath(os.path.dirname(__file__)) - return os.path.join(pkgdir, "templates") diff --git a/ablog/blog.py b/ablog/blog.py index 6eab2822..d391ddb9 100644 --- a/ablog/blog.py +++ b/ablog/blog.py @@ -91,37 +91,38 @@ def verify_fn(key, value, config): CONFIG = [ # name, default, rebuild, verify_fn # where verify_fn is (key, value, app.config) --> value, throwing a KeyError if the value isn't right - ("blog_path", "blog", True, require_config_type(str)), - ("blog_title", "Blog", True, require_config_type(str)), - ("blog_baseurl", "", True, require_config_type(str)), ("blog_archive_titles", None, False, require_config_type(bool)), + ("blog_authors", {}, True, require_config_full_name_link_dict()), + ("blog_baseurl", "", True, require_config_type(str)), + ("blog_default_author", None, True, require_config_str_or_list_lookup("blog_authors")), + ("blog_default_language", None, True, require_config_str_or_list_lookup("blog_languages")), + ("blog_default_location", None, True, require_config_str_or_list_lookup("blog_locations")), ("blog_feed_archives", False, True), ("blog_feed_fulltext", False, True), + ("blog_feed_length", None, None), ("blog_feed_subtitle", None, True), - ("blog_feed_titles", None, False), ("blog_feed_templates", {"atom": {}}, True), - ("blog_feed_length", None, None), - ("blog_authors", {}, True, require_config_full_name_link_dict()), - ("blog_default_author", None, True, require_config_str_or_list_lookup("blog_authors")), - ("blog_locations", {}, True, require_config_full_name_link_dict()), - ("blog_default_location", None, True, require_config_str_or_list_lookup("blog_locations")), + ("blog_feed_titles", None, False), ("blog_languages", {}, True, require_config_full_name_link_dict()), - ("blog_default_language", None, True, require_config_str_or_list_lookup("blog_languages")), - ("fontawesome_link_cdn", None, True), - ("fontawesome_included", False, True, require_config_type(bool)), + ("blog_locations", {}, True, require_config_full_name_link_dict()), + ("blog_path", "blog", True, require_config_type(str)), + ("blog_post_pattern", [], True, require_config_type((str, list))), + ("blog_title", "Blog", True, require_config_type(str)), + ("disqus_drafts", False, True), + ("disqus_pages", False, True), + ("disqus_shortname", None, True), ("fontawesome_css_file", "", True, require_config_type(str)), - ("post_date_format", "%d %B %Y", True, require_config_type(str)), - ("post_date_format_short", "%d %B", True, require_config_type(str)), - ("post_auto_orphan", True, True, require_config_type(bool)), - ("post_auto_image", 0, True), + ("fontawesome_included", False, True, require_config_type(bool)), + ("fontawesome_link_cdn", None, True), + ("post_always_section", False, True), ("post_auto_excerpt", 1, True), + ("post_auto_image", 0, True), + ("post_auto_orphan", True, True, require_config_type(bool)), + ("post_date_format_short", "%d %B", True, require_config_type(str)), + ("post_date_format", "%d %B %Y", True, require_config_type(str)), ("post_redirect_refresh", 5, True), - ("post_always_section", False, True), ("post_show_prev_next", True, True), - ("disqus_shortname", None, True), - ("disqus_drafts", False, True), - ("disqus_pages", False, True), - ("blog_post_pattern", [], True, require_config_type((str, list))), + ("skip_injecting_base_ablog_templates", False, True), ] TOMORROW = datetime.today() + dtmod.timedelta(1) TOMORROW = TOMORROW.replace(hour=0, minute=0, second=0, microsecond=0) @@ -129,7 +130,7 @@ def verify_fn(key, value, config): def revise_pending_xrefs(doctree, docname): - for node in doctree.traverse(addnodes.pending_xref): + for node in doctree.findall(addnodes.pending_xref): node["refdoc"] = docname diff --git a/ablog/locales/ca/LC_MESSAGES/sphinx.po b/ablog/locales/ca/LC_MESSAGES/sphinx.po index a4330d74..d5b5d0a3 100644 --- a/ablog/locales/ca/LC_MESSAGES/sphinx.po +++ b/ablog/locales/ca/LC_MESSAGES/sphinx.po @@ -22,7 +22,7 @@ msgstr "" msgid "Updated on " msgstr "Actualitzat el " -#: ablog/post.py:601 ablog/templates/authors.html:2 +#: ablog/post.py:601 ablog/templates/ablog/authors.html:2 msgid "Authors" msgstr "Autors" @@ -30,7 +30,7 @@ msgstr "Autors" msgid "Posts by" msgstr "Publicacions de" -#: ablog/post.py:602 ablog/templates/locations.html:3 +#: ablog/post.py:602 ablog/templates/ablog/locations.html:3 msgid "Locations" msgstr "Ubicacions" @@ -38,7 +38,7 @@ msgstr "Ubicacions" msgid "Posts from" msgstr "Publicacions des de" -#: ablog/post.py:603 ablog/templates/languages.html:3 +#: ablog/post.py:603 ablog/templates/ablog/languages.html:3 msgid "Languages" msgstr "Idiomes" @@ -46,7 +46,7 @@ msgstr "Idiomes" msgid "Posts in" msgstr "Publicacions en" -#: ablog/post.py:604 ablog/templates/categories.html:3 +#: ablog/post.py:604 ablog/templates/ablog/categories.html:3 msgid "Categories" msgstr "Categories" @@ -58,8 +58,8 @@ msgstr "Totes les publicacions" msgid "Posted in" msgstr "Publicat al" -#: ablog/post.py:606 ablog/templates/postcard2.html:57 -#: ablog/templates/tagcloud.html:2 +#: ablog/post.py:606 ablog/templates/ablog/postcard2.html:57 +#: ablog/templates/ablog/tagcloud.html:2 msgid "Tags" msgstr "Etiquetes" @@ -79,46 +79,46 @@ msgstr "Totes les" msgid "Drafts" msgstr "Borradors" -#: ablog/templates/archives.html:3 +#: ablog/templates/ablog/archives.html:3 msgid "Archives" msgstr "Arxius" -#: ablog/templates/collection.html:47 +#: ablog/templates/ablog/collection.html:47 msgid "Read more ..." msgstr "Llegir-ne més ..." -#: ablog/templates/postcard2.html:5 +#: ablog/templates/ablog/postcard2.html:5 msgid "Update" msgstr "Actualització" -#: ablog/templates/postcard2.html:12 +#: ablog/templates/ablog/postcard2.html:12 msgid "Author" msgstr "Autor" -#: ablog/templates/postcard2.html:24 +#: ablog/templates/ablog/postcard2.html:24 msgid "Location" msgstr "Ubicació" -#: ablog/templates/postcard2.html:35 +#: ablog/templates/ablog/postcard2.html:35 msgid "Language" msgstr "Idioma" -#: ablog/templates/postcard2.html:46 +#: ablog/templates/ablog/postcard2.html:46 msgid "Category" msgstr "Categoria" -#: ablog/templates/postcard2.html:60 +#: ablog/templates/ablog/postcard2.html:60 msgid "Tag" msgstr "Etiqueta" -#: ablog/templates/postnavy.html:5 +#: ablog/templates/ablog/postnavy.html:5 msgid "Previous" msgstr "Anterior" -#: ablog/templates/postnavy.html:15 +#: ablog/templates/ablog/postnavy.html:15 msgid "Next" msgstr "Següent" -#: ablog/templates/recentposts.html:3 +#: ablog/templates/ablog/recentposts.html:3 msgid "Recent Posts" msgstr "Publicacions recents" diff --git a/ablog/locales/de/LC_MESSAGES/sphinx.po b/ablog/locales/de/LC_MESSAGES/sphinx.po index e763b7c1..f7477264 100644 --- a/ablog/locales/de/LC_MESSAGES/sphinx.po +++ b/ablog/locales/de/LC_MESSAGES/sphinx.po @@ -21,7 +21,7 @@ msgstr "" msgid "Updated on" msgstr "Aktualisiert am" -#: ablog/post.py:387 ablog/templates/authors.html:2 +#: ablog/post.py:387 ablog/templates/ablog/authors.html:2 msgid "Authors" msgstr "Autoren" @@ -29,7 +29,7 @@ msgstr "Autoren" msgid "Posts by" msgstr "Einträge von" -#: ablog/post.py:388 ablog/templates/locations.html:2 +#: ablog/post.py:388 ablog/templates/ablog/locations.html:2 msgid "Locations" msgstr "Orte" @@ -37,7 +37,7 @@ msgstr "Orte" msgid "Posts from" msgstr "Einträge aus" -#: ablog/post.py:389 ablog/templates/languages.html:2 +#: ablog/post.py:389 ablog/templates/ablog/languages.html:2 msgid "Languages" msgstr "Sprachen" @@ -45,7 +45,7 @@ msgstr "Sprachen" msgid "Posts in" msgstr "Einträge in" -#: ablog/post.py:390 ablog/templates/categories.html:2 +#: ablog/post.py:390 ablog/templates/ablog/categories.html:2 msgid "Categories" msgstr "Kategorien" @@ -57,8 +57,8 @@ msgstr "Alle Einträge" msgid "Posted in" msgstr "Einträge in" -#: ablog/post.py:392 ablog/templates/postcard2.html:43 -#: ablog/templates/tagcloud.html:2 +#: ablog/post.py:392 ablog/templates/ablog/postcard2.html:43 +#: ablog/templates/ablog/tagcloud.html:2 msgid "Tags" msgstr "Schlagworte" @@ -70,46 +70,46 @@ msgstr "Einträge mit Schlagwort" msgid "Drafts" msgstr "Entwurf" -#: ablog/templates/archive.html:49 +#: ablog/templates/ablog/archive.html:49 msgid "Read more ..." msgstr "Weiter..." -#: ablog/templates/archives.html:2 +#: ablog/templates/ablog/archives.html:2 msgid "Archives" msgstr "Archive" -#: ablog/templates/postcard2.html:2 +#: ablog/templates/ablog/postcard2.html:2 msgid "Update" msgstr "Aktualisierung" -#: ablog/templates/postcard2.html:7 +#: ablog/templates/ablog/postcard2.html:7 msgid "Author" msgstr "Autor" -#: ablog/templates/postcard2.html:16 +#: ablog/templates/ablog/postcard2.html:16 msgid "Location" msgstr "Ort" -#: ablog/templates/postcard2.html:25 +#: ablog/templates/ablog/postcard2.html:25 msgid "Language" msgstr "Sprache" -#: ablog/templates/postcard2.html:34 +#: ablog/templates/ablog/postcard2.html:34 msgid "Category" msgstr "Kategorie" -#: ablog/templates/postcard2.html:44 +#: ablog/templates/ablog/postcard2.html:44 msgid "Tag" msgstr "Schlagwort" -#: ablog/templates/postnavy.html:7 +#: ablog/templates/ablog/postnavy.html:7 msgid "Previous" msgstr "Vorige" -#: ablog/templates/postnavy.html:17 +#: ablog/templates/ablog/postnavy.html:17 msgid "Next" msgstr "Nächste" -#: ablog/templates/recentposts.html:2 +#: ablog/templates/ablog/recentposts.html:2 msgid "Recent Posts" msgstr "Neue Einträge" diff --git a/ablog/locales/es/LC_MESSAGES/sphinx.po b/ablog/locales/es/LC_MESSAGES/sphinx.po index 850e5620..7c62a61f 100644 --- a/ablog/locales/es/LC_MESSAGES/sphinx.po +++ b/ablog/locales/es/LC_MESSAGES/sphinx.po @@ -22,7 +22,7 @@ msgstr "" msgid "Updated on" msgstr "Actualizado el" -#: ablog/post.py:387 ablog/templates/authors.html:2 +#: ablog/post.py:387 ablog/templates/ablog/authors.html:2 msgid "Authors" msgstr "Autores" @@ -30,7 +30,7 @@ msgstr "Autores" msgid "Posts by" msgstr "Entradas por" -#: ablog/post.py:388 ablog/templates/locations.html:2 +#: ablog/post.py:388 ablog/templates/ablog/locations.html:2 msgid "Locations" msgstr "Lugares" @@ -38,7 +38,7 @@ msgstr "Lugares" msgid "Posts from" msgstr "Entradas desde" -#: ablog/post.py:389 ablog/templates/languages.html:2 +#: ablog/post.py:389 ablog/templates/ablog/languages.html:2 msgid "Languages" msgstr "Idiomas" @@ -46,7 +46,7 @@ msgstr "Idiomas" msgid "Posts in" msgstr "Entradas en" -#: ablog/post.py:390 ablog/templates/categories.html:2 +#: ablog/post.py:390 ablog/templates/ablog/categories.html:2 msgid "Categories" msgstr "Categorías" @@ -58,8 +58,8 @@ msgstr "Todas las entradas" msgid "Posted in" msgstr "Publicado en" -#: ablog/post.py:392 ablog/templates/postcard2.html:43 -#: ablog/templates/tagcloud.html:2 +#: ablog/post.py:392 ablog/templates/ablog/postcard2.html:43 +#: ablog/templates/ablog/tagcloud.html:2 msgid "Tags" msgstr "Etiquetas" @@ -71,46 +71,46 @@ msgstr "Entradas etiquetadas" msgid "Drafts" msgstr "Borradores" -#: ablog/templates/archive.html:49 +#: ablog/templates/ablog/archive.html:49 msgid "Read more ..." msgstr "Leer más ..." -#: ablog/templates/archives.html:2 +#: ablog/templates/ablog/archives.html:2 msgid "Archives" msgstr "Archivos" -#: ablog/templates/postcard2.html:2 +#: ablog/templates/ablog/postcard2.html:2 msgid "Update" msgstr "Actualizado" -#: ablog/templates/postcard2.html:7 +#: ablog/templates/ablog/postcard2.html:7 msgid "Author" msgstr "Autor" -#: ablog/templates/postcard2.html:16 +#: ablog/templates/ablog/postcard2.html:16 msgid "Location" msgstr "Lugar" -#: ablog/templates/postcard2.html:25 +#: ablog/templates/ablog/postcard2.html:25 msgid "Language" msgstr "Idioma" -#: ablog/templates/postcard2.html:34 +#: ablog/templates/ablog/postcard2.html:34 msgid "Category" msgstr "Categoría" -#: ablog/templates/postcard2.html:44 +#: ablog/templates/ablog/postcard2.html:44 msgid "Tag" msgstr "Etiqueta" -#: ablog/templates/postnavy.html:7 +#: ablog/templates/ablog/postnavy.html:7 msgid "Previous" msgstr "Anterior" -#: ablog/templates/postnavy.html:17 +#: ablog/templates/ablog/postnavy.html:17 msgid "Next" msgstr "Siguiente" -#: ablog/templates/recentposts.html:2 +#: ablog/templates/ablog/recentposts.html:2 msgid "Recent Posts" msgstr "Entradas recientes" diff --git a/ablog/locales/et/LC_MESSAGES/sphinx.po b/ablog/locales/et/LC_MESSAGES/sphinx.po index daa43898..579fd266 100644 --- a/ablog/locales/et/LC_MESSAGES/sphinx.po +++ b/ablog/locales/et/LC_MESSAGES/sphinx.po @@ -21,7 +21,7 @@ msgstr "" msgid "Updated on" msgstr "Uuendus" -#: ablog/post.py:387 ablog/templates/authors.html:2 +#: ablog/post.py:387 ablog/templates/ablog/authors.html:2 msgid "Authors" msgstr "Autorid" @@ -29,7 +29,7 @@ msgstr "Autorid" msgid "Posts by" msgstr "Postitused autorilt" -#: ablog/post.py:388 ablog/templates/locations.html:2 +#: ablog/post.py:388 ablog/templates/ablog/locations.html:2 msgid "Locations" msgstr "Kohad" @@ -37,7 +37,7 @@ msgstr "Kohad" msgid "Posts from" msgstr "" -#: ablog/post.py:389 ablog/templates/languages.html:2 +#: ablog/post.py:389 ablog/templates/ablog/languages.html:2 msgid "Languages" msgstr "Keeltes" @@ -45,7 +45,7 @@ msgstr "Keeltes" msgid "Posts in" msgstr "" -#: ablog/post.py:390 ablog/templates/categories.html:2 +#: ablog/post.py:390 ablog/templates/ablog/categories.html:2 msgid "Categories" msgstr "Kategooriad" @@ -57,8 +57,8 @@ msgstr "Kõik postitused" msgid "Posted in" msgstr "Postitused kategoorias" -#: ablog/post.py:392 ablog/templates/postcard2.html:43 -#: ablog/templates/tagcloud.html:2 +#: ablog/post.py:392 ablog/templates/ablog/postcard2.html:43 +#: ablog/templates/ablog/tagcloud.html:2 msgid "Tags" msgstr "Märksõnad" @@ -70,46 +70,46 @@ msgstr "Postitused märksõnaga" msgid "Drafts" msgstr "Eelnõu" -#: ablog/templates/archive.html:49 +#: ablog/templates/ablog/archive.html:49 msgid "Read more ..." msgstr "Edasi..." -#: ablog/templates/archives.html:2 +#: ablog/templates/ablog/archives.html:2 msgid "Archives" msgstr "Arhiiv" -#: ablog/templates/postcard2.html:2 +#: ablog/templates/ablog/postcard2.html:2 msgid "Update" msgstr "Ajakohastama" -#: ablog/templates/postcard2.html:7 +#: ablog/templates/ablog/postcard2.html:7 msgid "Author" msgstr "Autor" -#: ablog/templates/postcard2.html:16 +#: ablog/templates/ablog/postcard2.html:16 msgid "Location" msgstr "Koht" -#: ablog/templates/postcard2.html:25 +#: ablog/templates/ablog/postcard2.html:25 msgid "Language" msgstr "Keel" -#: ablog/templates/postcard2.html:34 +#: ablog/templates/ablog/postcard2.html:34 msgid "Category" msgstr "Kategooria" -#: ablog/templates/postcard2.html:44 +#: ablog/templates/ablog/postcard2.html:44 msgid "Tag" msgstr "Märksõna" -#: ablog/templates/postnavy.html:7 +#: ablog/templates/ablog/postnavy.html:7 msgid "Previous" msgstr "Eelmine" -#: ablog/templates/postnavy.html:17 +#: ablog/templates/ablog/postnavy.html:17 msgid "Next" msgstr "Järgmine" -#: ablog/templates/recentposts.html:2 +#: ablog/templates/ablog/recentposts.html:2 msgid "Recent Posts" msgstr "Viimased postitused" diff --git a/ablog/locales/fr/LC_MESSAGES/sphinx.po b/ablog/locales/fr/LC_MESSAGES/sphinx.po index 09a7e22c..f258d3d8 100644 --- a/ablog/locales/fr/LC_MESSAGES/sphinx.po +++ b/ablog/locales/fr/LC_MESSAGES/sphinx.po @@ -18,7 +18,7 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Generated-By: Babel 2.8.0\n" -#: ablog/post.py:525 ablog/templates/authors.html:2 +#: ablog/post.py:525 ablog/templates/ablog/authors.html:2 msgid "Authors" msgstr "Auteurs" @@ -26,7 +26,7 @@ msgstr "Auteurs" msgid "Posts by" msgstr "Billets par" -#: ablog/post.py:526 ablog/templates/locations.html:2 +#: ablog/post.py:526 ablog/templates/ablog/locations.html:2 msgid "Locations" msgstr "Lieux" @@ -34,7 +34,7 @@ msgstr "Lieux" msgid "Posts from" msgstr "Billets depuis" -#: ablog/post.py:527 ablog/templates/languages.html:2 +#: ablog/post.py:527 ablog/templates/ablog/languages.html:2 msgid "Languages" msgstr "Langues" @@ -42,7 +42,7 @@ msgstr "Langues" msgid "Posts in" msgstr "Billets dans" -#: ablog/post.py:528 ablog/templates/categories.html:2 +#: ablog/post.py:528 ablog/templates/ablog/categories.html:2 msgid "Categories" msgstr "Catégories" @@ -54,8 +54,8 @@ msgstr "Tous les billets" msgid "Posted in" msgstr "Publié dans" -#: ablog/post.py:530 ablog/templates/postcard2.html:43 -#: ablog/templates/tagcloud.html:2 +#: ablog/post.py:530 ablog/templates/ablog/postcard2.html:43 +#: ablog/templates/ablog/tagcloud.html:2 msgid "Tags" msgstr "Tags" @@ -75,46 +75,46 @@ msgstr "Tous les billets" msgid "Drafts" msgstr "Brouillons" -#: ablog/templates/archives.html:2 +#: ablog/templates/ablog/archives.html:2 msgid "Archives" msgstr "Archives" -#: ablog/templates/collection.html:48 +#: ablog/templates/ablog/collection.html:48 msgid "Read more ..." msgstr "Lire plus…" -#: ablog/templates/postcard2.html:2 +#: ablog/templates/ablog/postcard2.html:2 msgid "Update" msgstr "Mis à jour" -#: ablog/templates/postcard2.html:7 +#: ablog/templates/ablog/postcard2.html:7 msgid "Author" msgstr "Auteur" -#: ablog/templates/postcard2.html:16 +#: ablog/templates/ablog/postcard2.html:16 msgid "Location" msgstr "Lieu" -#: ablog/templates/postcard2.html:25 +#: ablog/templates/ablog/postcard2.html:25 msgid "Language" msgstr "Langue" -#: ablog/templates/postcard2.html:34 +#: ablog/templates/ablog/postcard2.html:34 msgid "Category" msgstr "Catégorie" -#: ablog/templates/postcard2.html:44 +#: ablog/templates/ablog/postcard2.html:44 msgid "Tag" msgstr "Tag" -#: ablog/templates/postnavy.html:7 +#: ablog/templates/ablog/postnavy.html:7 msgid "Previous" msgstr "Précédent" -#: ablog/templates/postnavy.html:17 +#: ablog/templates/ablog/postnavy.html:17 msgid "Next" msgstr "Suivant" -#: ablog/templates/recentposts.html:2 +#: ablog/templates/ablog/recentposts.html:2 msgid "Recent Posts" msgstr "Billets récents" diff --git a/ablog/locales/ru/LC_MESSAGES/sphinx.po b/ablog/locales/ru/LC_MESSAGES/sphinx.po index 63edab0a..d117a471 100644 --- a/ablog/locales/ru/LC_MESSAGES/sphinx.po +++ b/ablog/locales/ru/LC_MESSAGES/sphinx.po @@ -23,7 +23,7 @@ msgstr "" msgid "Updated on" msgstr "Обновлено" -#: ablog/post.py:387 ablog/templates/authors.html:2 +#: ablog/post.py:387 ablog/templates/ablog/authors.html:2 msgid "Authors" msgstr "Авторы" @@ -31,7 +31,7 @@ msgstr "Авторы" msgid "Posts by" msgstr "Опубликовано" -#: ablog/post.py:388 ablog/templates/locations.html:2 +#: ablog/post.py:388 ablog/templates/ablog/locations.html:2 msgid "Locations" msgstr "" @@ -39,7 +39,7 @@ msgstr "" msgid "Posts from" msgstr "Сообщения из" -#: ablog/post.py:389 ablog/templates/languages.html:2 +#: ablog/post.py:389 ablog/templates/ablog/languages.html:2 msgid "Languages" msgstr "Языки" @@ -47,7 +47,7 @@ msgstr "Языки" msgid "Posts in" msgstr "Сообщений в" -#: ablog/post.py:390 ablog/templates/categories.html:2 +#: ablog/post.py:390 ablog/templates/ablog/categories.html:2 msgid "Categories" msgstr "Категории" @@ -59,8 +59,8 @@ msgstr "Все записи" msgid "Posted in" msgstr "Опубликовано в" -#: ablog/post.py:392 ablog/templates/postcard2.html:43 -#: ablog/templates/tagcloud.html:2 +#: ablog/post.py:392 ablog/templates/ablog/postcard2.html:43 +#: ablog/templates/ablog/tagcloud.html:2 msgid "Tags" msgstr "Теги" @@ -72,46 +72,46 @@ msgstr "Сообщения с тегом" msgid "Drafts" msgstr "Черновик" -#: ablog/templates/archive.html:49 +#: ablog/templates/ablog/archive.html:49 msgid "Read more ..." msgstr "Читать ..." -#: ablog/templates/archives.html:2 +#: ablog/templates/ablog/archives.html:2 msgid "Archives" msgstr "Архив" -#: ablog/templates/postcard2.html:2 +#: ablog/templates/ablog/postcard2.html:2 msgid "Update" msgstr "Обновить" -#: ablog/templates/postcard2.html:7 +#: ablog/templates/ablog/postcard2.html:7 msgid "Author" msgstr "Автор" -#: ablog/templates/postcard2.html:16 +#: ablog/templates/ablog/postcard2.html:16 msgid "Location" msgstr "Расположение" -#: ablog/templates/postcard2.html:25 +#: ablog/templates/ablog/postcard2.html:25 msgid "Language" msgstr "Язык" -#: ablog/templates/postcard2.html:34 +#: ablog/templates/ablog/postcard2.html:34 msgid "Category" msgstr "Категория" -#: ablog/templates/postcard2.html:44 +#: ablog/templates/ablog/postcard2.html:44 msgid "Tag" msgstr "Тег" -#: ablog/templates/postnavy.html:7 +#: ablog/templates/ablog/postnavy.html:7 msgid "Previous" msgstr "Предыдущий" -#: ablog/templates/postnavy.html:17 +#: ablog/templates/ablog/postnavy.html:17 msgid "Next" msgstr "Следующий" -#: ablog/templates/recentposts.html:2 +#: ablog/templates/ablog/recentposts.html:2 msgid "Recent Posts" msgstr "Недавние Записи" diff --git a/ablog/locales/tr/LC_MESSAGES/sphinx.po b/ablog/locales/tr/LC_MESSAGES/sphinx.po index bd79826f..8652d2e5 100644 --- a/ablog/locales/tr/LC_MESSAGES/sphinx.po +++ b/ablog/locales/tr/LC_MESSAGES/sphinx.po @@ -21,7 +21,7 @@ msgstr "" msgid "Updated on" msgstr "Güncelleme" -#: ablog/post.py:387 ablog/templates/authors.html:2 +#: ablog/post.py:387 ablog/templates/ablog/authors.html:2 msgid "Authors" msgstr "Yazarlar" @@ -29,7 +29,7 @@ msgstr "Yazarlar" msgid "Posts by" msgstr "Yazar" -#: ablog/post.py:388 ablog/templates/locations.html:2 +#: ablog/post.py:388 ablog/templates/ablog/locations.html:2 msgid "Locations" msgstr "Mevkiler" @@ -37,7 +37,7 @@ msgstr "Mevkiler" msgid "Posts from" msgstr "Mevki" -#: ablog/post.py:389 ablog/templates/languages.html:2 +#: ablog/post.py:389 ablog/templates/ablog/languages.html:2 msgid "Languages" msgstr "Diller" @@ -45,7 +45,7 @@ msgstr "Diller" msgid "Posts in" msgstr "Kategori" -#: ablog/post.py:390 ablog/templates/categories.html:2 +#: ablog/post.py:390 ablog/templates/ablog/categories.html:2 msgid "Categories" msgstr "Kategoriler" @@ -57,8 +57,8 @@ msgstr "Bütün yazılar" msgid "Posted in" msgstr "Sene" -#: ablog/post.py:392 ablog/templates/postcard2.html:43 -#: ablog/templates/tagcloud.html:2 +#: ablog/post.py:392 ablog/templates/ablog/postcard2.html:43 +#: ablog/templates/ablog/tagcloud.html:2 msgid "Tags" msgstr "Etiketler" @@ -70,46 +70,46 @@ msgstr "Etiket" msgid "Drafts" msgstr "Taslaklar" -#: ablog/templates/archive.html:49 +#: ablog/templates/ablog/archive.html:49 msgid "Read more ..." msgstr "Okumaya devam et ..." -#: ablog/templates/archives.html:2 +#: ablog/templates/ablog/archives.html:2 msgid "Archives" msgstr "Arşiv" -#: ablog/templates/postcard2.html:2 +#: ablog/templates/ablog/postcard2.html:2 msgid "Update" msgstr "Güncelleme" -#: ablog/templates/postcard2.html:7 +#: ablog/templates/ablog/postcard2.html:7 msgid "Author" msgstr "Yazar" -#: ablog/templates/postcard2.html:16 +#: ablog/templates/ablog/postcard2.html:16 msgid "Location" msgstr "Mevki" -#: ablog/templates/postcard2.html:25 +#: ablog/templates/ablog/postcard2.html:25 msgid "Language" msgstr "Dil" -#: ablog/templates/postcard2.html:34 +#: ablog/templates/ablog/postcard2.html:34 msgid "Category" msgstr "Kategori" -#: ablog/templates/postcard2.html:44 +#: ablog/templates/ablog/postcard2.html:44 msgid "Tag" msgstr "Etiket" -#: ablog/templates/postnavy.html:7 +#: ablog/templates/ablog/postnavy.html:7 msgid "Previous" msgstr "Önceki" -#: ablog/templates/postnavy.html:17 +#: ablog/templates/ablog/postnavy.html:17 msgid "Next" msgstr "Sonraki" -#: ablog/templates/recentposts.html:2 +#: ablog/templates/ablog/recentposts.html:2 msgid "Recent Posts" msgstr "Yeni Yazılar" diff --git a/ablog/locales/zh_CN/LC_MESSAGES/sphinx.po b/ablog/locales/zh_CN/LC_MESSAGES/sphinx.po index 588e32d4..7f213e8d 100644 --- a/ablog/locales/zh_CN/LC_MESSAGES/sphinx.po +++ b/ablog/locales/zh_CN/LC_MESSAGES/sphinx.po @@ -18,7 +18,7 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Generated-By: Babel 2.7.0\n" -#: ablog/post.py:525 ablog/templates/authors.html:2 +#: ablog/post.py:525 ablog/templates/ablog/authors.html:2 msgid "Authors" msgstr "作者" @@ -26,7 +26,7 @@ msgstr "作者" msgid "Posts by" msgstr "文章" -#: ablog/post.py:526 ablog/templates/locations.html:2 +#: ablog/post.py:526 ablog/templates/ablog/locations.html:2 msgid "Locations" msgstr "地点" @@ -34,7 +34,7 @@ msgstr "地点" msgid "Posts from" msgstr "文章自" -#: ablog/post.py:527 ablog/templates/languages.html:2 +#: ablog/post.py:527 ablog/templates/ablog/languages.html:2 msgid "Languages" msgstr "语言" @@ -42,7 +42,7 @@ msgstr "语言" msgid "Posts in" msgstr "文章:" -#: ablog/post.py:528 ablog/templates/categories.html:2 +#: ablog/post.py:528 ablog/templates/ablog/categories.html:2 msgid "Categories" msgstr "类别" @@ -54,8 +54,8 @@ msgstr "所有文章" msgid "Posted in" msgstr "文章:" -#: ablog/post.py:530 ablog/templates/postcard2.html:43 -#: ablog/templates/tagcloud.html:2 +#: ablog/post.py:530 ablog/templates/ablog/postcard2.html:43 +#: ablog/templates/ablog/tagcloud.html:2 msgid "Tags" msgstr "标签" @@ -75,46 +75,46 @@ msgstr "所有" msgid "Drafts" msgstr "草稿" -#: ablog/templates/archives.html:2 +#: ablog/templates/ablog/archives.html:2 msgid "Archives" msgstr "归档" -#: ablog/templates/collection.html:48 +#: ablog/templates/ablog/collection.html:48 msgid "Read more ..." msgstr "更多 ..." -#: ablog/templates/postcard2.html:2 +#: ablog/templates/ablog/postcard2.html:2 msgid "Update" msgstr "更新" -#: ablog/templates/postcard2.html:7 +#: ablog/templates/ablog/postcard2.html:7 msgid "Author" msgstr "作者" -#: ablog/templates/postcard2.html:16 +#: ablog/templates/ablog/postcard2.html:16 msgid "Location" msgstr "地点" -#: ablog/templates/postcard2.html:25 +#: ablog/templates/ablog/postcard2.html:25 msgid "Language" msgstr "语言" -#: ablog/templates/postcard2.html:34 +#: ablog/templates/ablog/postcard2.html:34 msgid "Category" msgstr "类别" -#: ablog/templates/postcard2.html:44 +#: ablog/templates/ablog/postcard2.html:44 msgid "Tag" msgstr "标签" -#: ablog/templates/postnavy.html:7 +#: ablog/templates/ablog/postnavy.html:7 msgid "Previous" msgstr "上一篇" -#: ablog/templates/postnavy.html:17 +#: ablog/templates/ablog/postnavy.html:17 msgid "Next" msgstr "下一篇" -#: ablog/templates/recentposts.html:2 +#: ablog/templates/ablog/recentposts.html:2 msgid "Recent Posts" msgstr "最近文章" diff --git a/ablog/post.py b/ablog/post.py index 3595302f..27a863b6 100644 --- a/ablog/post.py +++ b/ablog/post.py @@ -157,12 +157,12 @@ class CheckFrontMatter(SphinxTransform): def apply(self): # Check if page-level metadata has been given - docinfo = list(self.document.traverse(nodes.docinfo)) + docinfo = list(self.document.findall(nodes.docinfo)) if not docinfo: return None docinfo = docinfo[0] # Pull the metadata for the page to check if it is a blog post - metadata = {fn.children[0].astext(): fn.children[1].astext() for fn in docinfo.traverse(nodes.field)} + metadata = {fn.children[0].astext(): fn.children[1].astext() for fn in docinfo.findall(nodes.field)} tags = metadata.get("tags") if isinstance(tags, str): # myst_parser store front-matter field to TextNode in dict_to_fm_field_list. @@ -172,14 +172,14 @@ def apply(self): metadata["tags"] = ",".join( [t.strip().lstrip('"').lstrip("'").rstrip('"').rstrip("'") for t in tags.split(",")] ) - if list(docinfo.traverse(nodes.author)): - metadata["author"] = list(docinfo.traverse(nodes.author))[0].astext() + if list(docinfo.findall(nodes.author)): + metadata["author"] = list(docinfo.findall(nodes.author))[0].astext() # These two fields are special-cased in docutils - if list(docinfo.traverse(nodes.date)): - metadata["date"] = list(docinfo.traverse(nodes.date))[0].astext() + if list(docinfo.findall(nodes.date)): + metadata["date"] = list(docinfo.findall(nodes.date))[0].astext() if "blogpost" not in metadata and self.env.docname not in self.config.matched_blog_posts: return None - if self.document.traverse(PostNode): + if self.document.findall(PostNode): logging.warning(f"Found blog post front-matter as well as post directive, using post directive.") # Iterate through metadata and create a PostNode with relevant fields option_spec = PostDirective.option_spec @@ -197,7 +197,7 @@ def apply(self): if not metadata.get("excerpt"): blog = Blog(self.app) node["excerpt"] = blog.post_auto_excerpt - sections = list(self.document.traverse(nodes.section)) + sections = list(self.document.findall(nodes.section)) if sections: sections[0].children.append(node) node.parent = sections[0] @@ -239,7 +239,7 @@ def _get_section_title(section): """ Return section title as text. """ - for title in section.traverse(nodes.title): + for title in section.findall(nodes.title): return title.astext() raise Exception("Missing title") # A problem with the following is that title may contain pending @@ -250,7 +250,7 @@ def _get_update_dates(section, docname, post_date_format): """ Return list of dates of updates found section. """ - update_nodes = list(section.traverse(UpdateNode)) + update_nodes = list(section.findall(UpdateNode)) update_dates = [] for update_node in update_nodes: try: @@ -283,7 +283,7 @@ def process_posts(app, doctree): env = app.builder.env if not hasattr(env, "ablog_posts"): env.ablog_posts = {} - post_nodes = list(doctree.traverse(PostNode)) + post_nodes = list(doctree.findall(PostNode)) if not post_nodes: return post_date_format = app.config["post_date_format"] @@ -328,7 +328,7 @@ def process_posts(app, doctree): excerpt.append(child.deepcopy()) elif node["excerpt"]: count = 0 - for nod in section.traverse(nodes.paragraph): + for nod in section.findall(nodes.paragraph): excerpt.append(nod.deepcopy()) count += 1 if count >= (node["excerpt"] or 0): @@ -338,7 +338,7 @@ def process_posts(app, doctree): node.replace_self([]) nimg = node["image"] or blog.post_auto_image if nimg: - for img, nod in enumerate(section.traverse(nodes.image), start=1): + for img, nod in enumerate(section.findall(nodes.image), start=1): if img == nimg: excerpt.append(nod.deepcopy()) break @@ -381,7 +381,7 @@ def process_posts(app, doctree): else: section_copy = section.deepcopy() # multiple posting may result having post nodes - for nn in section_copy.traverse(PostNode): + for nn in section_copy.findall(PostNode): if nn["exclude"]: nn.replace_self([]) else: @@ -433,7 +433,7 @@ def process_postlist(app, doctree, docname): blog = Blog(app) if not blog: register_posts(app) - for node in doctree.traverse(PostList): + for node in doctree.findall(PostList): colls = [] for cat in ["tags", "author", "category", "location", "language"]: for coll in node[cat]: @@ -554,7 +554,7 @@ def generate_archive_pages(app): blog = Blog(app) for post in blog.posts: for redirect in post.redirect: - yield (redirect, {"redirect": post.docname, "post": post}, "redirect.html") + yield (redirect, {"redirect": post.docname, "post": post}, "ablog/redirect.html") found_docs = app.env.found_docs atom_feed = bool(blog.blog_baseurl) feed_archives = blog.blog_feed_archives @@ -571,7 +571,7 @@ def generate_archive_pages(app): continue context = {"parents": [], "title": title, "header": header, "catalog": catalog, "summary": True} if catalog.docname not in found_docs: - yield (catalog.docname, context, "catalog.html") + yield (catalog.docname, context, "ablog/catalog.html") for collection in catalog: if not collection: continue @@ -586,7 +586,7 @@ def generate_archive_pages(app): } context["feed_title"] = context["title"] if collection.docname not in found_docs: - yield (collection.docname, context, "collection.html") + yield (collection.docname, context, "ablog/collection.html") if 1: context = { "parents": [], @@ -598,9 +598,9 @@ def generate_archive_pages(app): "feed_path": blog.blog_path, } docname = blog.posts.docname - yield (docname, context, "collection.html") + yield (docname, context, "ablog/collection.html") context = {"parents": [], "title": _("Drafts"), "collection": blog.drafts, "summary": True} - yield (blog.drafts.docname, context, "collection.html") + yield (blog.drafts.docname, context, "ablog/collection.html") def generate_atom_feeds(app): diff --git a/ablog/start.py b/ablog/start.py index d0b6d9c7..3389df73 100644 --- a/ablog/start.py +++ b/ablog/start.py @@ -77,6 +77,11 @@ def w(t, ls=80): # 'Earth': ('The Blue Planet', 'https://en.wikipedia.org/wiki/Earth), # }} +# This will prevent ablog from injecting its own templates into the Sphinx +# build. This is only useful when you have a custom template bridge (rare). +# See https://github.com/sunpy/ablog/pull/144 for the full context. +# skip_injecting_base_ablog_templates = False + # -- Blog Post Related -------------------------------------------------------- # Format date for a post. @@ -123,10 +128,9 @@ def w(t, ls=80): # In addition, there are authors.html, languages.html, and locations.html # sidebars that link to author and location archive pages. html_sidebars = {{ - '**': [ 'about.html', - 'postcard.html', 'navigation.html', - 'recentposts.html', 'tagcloud.html', - 'categories.html', 'archives.html', + '**': [ 'ablog/postcard.html', 'navigation.html', + 'ablog/recentposts.html', 'ablog/tagcloud.html', + 'ablog/categories.html', 'ablog/archives.html', 'searchbox.html', ], }} @@ -215,9 +219,6 @@ def w(t, ls=80): 'ablog', ] -# Add any paths that contain templates here, relative to this directory. -templates_path = ["{dot}templates", ablog.get_html_templates_path()] - # The suffix(es) of source filenames. source_suffix = "{suffix}" diff --git a/ablog/templates/ablog/archives.html b/ablog/templates/ablog/archives.html new file mode 100644 index 00000000..d846d137 --- /dev/null +++ b/ablog/templates/ablog/archives.html @@ -0,0 +1,16 @@ +{% if ablog.archive %} +
+{% endif %} diff --git a/ablog/templates/ablog/authors.html b/ablog/templates/ablog/authors.html new file mode 100644 index 00000000..fbf0bf5a --- /dev/null +++ b/ablog/templates/ablog/authors.html @@ -0,0 +1,12 @@ +{% if ablog.author %} + +{% endif %} diff --git a/ablog/templates/ablog/catalog.html b/ablog/templates/ablog/catalog.html new file mode 100644 index 00000000..dc333c60 --- /dev/null +++ b/ablog/templates/ablog/catalog.html @@ -0,0 +1,28 @@ +{%- extends "page.html" %} +{% block body %} +{% for collection in catalog %} +{% if collection %} ++ {% if post.published %} + {{ post.date.strftime(ablog.post_date_format) }} + {% else %} + Draft + {% endif %} + - + {{ post.title }} +
+- {% if fa %}{% endif %} {% if post.published %} {{ - post.date.strftime(ablog.post_date_format) }} {% else %} Draft {% endif %} + {% if post.published %} + {{ post.date.strftime(ablog.post_date_format) }} + {% else %} + Draft + {% endif %} - {{ post.title }}
- {% if 0 %} -
Comments
- - comments powered by Disqus + + + comments powered by Disqus +