From 0d064049a371ed2689980bbef837f37886f975ed Mon Sep 17 00:00:00 2001 From: Pradyun Gedam Date: Fri, 25 Feb 2022 15:46:05 +0000 Subject: [PATCH] Make newlines of all files consistent (#127) Co-authored-by: Pradyun Gedam --- ablog/__init__.py | 244 ++++++++++++++++---------------- ablog/templates/catalog.html | 52 +++---- ablog/templates/collection.html | 104 +++++++------- docs/make.bat | 70 ++++----- 4 files changed, 235 insertions(+), 235 deletions(-) diff --git a/ablog/__init__.py b/ablog/__init__.py index 6460e984..63da1972 100755 --- a/ablog/__init__.py +++ b/ablog/__init__.py @@ -1,122 +1,122 @@ -""" -ABlog for Sphinx. -""" - -import os -from glob import glob - -from .blog import CONFIG, Blog -from .post import ( - CheckFrontMatter, - PostDirective, - PostListDirective, - UpdateDirective, - UpdateNode, - generate_archive_pages, - generate_atom_feeds, - missing_reference, - process_postlist, - process_posts, - purge_posts, -) -from .version import version as __version__ - -__all__ = ["setup"] - - -def anchor(post): - """ - Return anchor string for posts that arepage sections. - """ - - if post.section: - return "#" + post.section - else: - return "" - - -def builder_support(builder): - """ - Return True when builder is supported. - - Supported builders output in html format, but exclude - `PickleHTMLBuilder` and `JSONHTMLBuilder`, which run into issues - when serializing blog objects. - """ - - if hasattr(builder, "builder"): - builder = builder.builder - - not_supported = {"json", "pickle"} - return builder.format == "html" and builder.name not in not_supported - - -def html_page_context(app, pagename, templatename, context, doctree): - - if builder_support(app): - context["ablog"] = blog = Blog(app) - context["anchor"] = anchor - # following is already available for archive pages - if blog.blog_baseurl and "feed_path" not in context: - context["feed_path"] = blog.blog_path - context["feed_title"] = blog.blog_title - - -def setup(app): - """ - Setup ABlog extension. - """ - - for args in CONFIG: - app.add_config_value(*args[:3]) - - app.add_directive("post", PostDirective) - app.add_directive("postlist", PostListDirective) - - app.connect("config-inited", config_inited) - app.connect("doctree-read", process_posts) - - app.connect("env-purge-doc", purge_posts) - app.connect("doctree-resolved", process_postlist) - app.connect("missing-reference", missing_reference) - app.connect("html-collect-pages", generate_archive_pages) - app.connect("html-collect-pages", generate_atom_feeds) - app.connect("html-page-context", html_page_context) - - app.add_transform(CheckFrontMatter) - app.add_directive("update", UpdateDirective) - app.add_node( - UpdateNode, - html=(lambda s, n: s.visit_admonition(n), lambda s, n: s.depart_admonition(n)), - latex=(lambda s, n: s.visit_admonition(n), lambda s, n: s.depart_admonition(n)), - ) - - pkgdir = os.path.abspath(os.path.dirname(__file__)) - 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) - matched_patterns.extend( - os.path.relpath(os.path.splitext(ii)[0], app.srcdir) 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") +""" +ABlog for Sphinx. +""" + +import os +from glob import glob + +from .blog import CONFIG, Blog +from .post import ( + CheckFrontMatter, + PostDirective, + PostListDirective, + UpdateDirective, + UpdateNode, + generate_archive_pages, + generate_atom_feeds, + missing_reference, + process_postlist, + process_posts, + purge_posts, +) +from .version import version as __version__ + +__all__ = ["setup"] + + +def anchor(post): + """ + Return anchor string for posts that arepage sections. + """ + + if post.section: + return "#" + post.section + else: + return "" + + +def builder_support(builder): + """ + Return True when builder is supported. + + Supported builders output in html format, but exclude + `PickleHTMLBuilder` and `JSONHTMLBuilder`, which run into issues + when serializing blog objects. + """ + + if hasattr(builder, "builder"): + builder = builder.builder + + not_supported = {"json", "pickle"} + return builder.format == "html" and builder.name not in not_supported + + +def html_page_context(app, pagename, templatename, context, doctree): + + if builder_support(app): + context["ablog"] = blog = Blog(app) + context["anchor"] = anchor + # following is already available for archive pages + if blog.blog_baseurl and "feed_path" not in context: + context["feed_path"] = blog.blog_path + context["feed_title"] = blog.blog_title + + +def setup(app): + """ + Setup ABlog extension. + """ + + for args in CONFIG: + app.add_config_value(*args[:3]) + + app.add_directive("post", PostDirective) + app.add_directive("postlist", PostListDirective) + + app.connect("config-inited", config_inited) + app.connect("doctree-read", process_posts) + + app.connect("env-purge-doc", purge_posts) + app.connect("doctree-resolved", process_postlist) + app.connect("missing-reference", missing_reference) + app.connect("html-collect-pages", generate_archive_pages) + app.connect("html-collect-pages", generate_atom_feeds) + app.connect("html-page-context", html_page_context) + + app.add_transform(CheckFrontMatter) + app.add_directive("update", UpdateDirective) + app.add_node( + UpdateNode, + html=(lambda s, n: s.visit_admonition(n), lambda s, n: s.depart_admonition(n)), + latex=(lambda s, n: s.visit_admonition(n), lambda s, n: s.depart_admonition(n)), + ) + + pkgdir = os.path.abspath(os.path.dirname(__file__)) + 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) + matched_patterns.extend( + os.path.relpath(os.path.splitext(ii)[0], app.srcdir) 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/templates/catalog.html b/ablog/templates/catalog.html index e9be0164..e2769ec1 100644 --- a/ablog/templates/catalog.html +++ b/ablog/templates/catalog.html @@ -1,26 +1,26 @@ -{%- extends "page.html" %} {% block body %} {% for collection in catalog %} {% -if collection %} -
-

- {{ header }} - {{ collection }} -

- {% for post in collection %} -
-

- {% if fa %}{% endif %} {% if post.published %} {{ - post.date.strftime(ablog.post_date_format) }} {% else %} Draft {% endif %} - - - {{ post.title }} -

- {% if 0 %} -
    - {% include "postcard2.html" %} -
- {% endif %} -
- {% endfor %} -
-{% endif %} {% endfor %} {% endblock %} +{%- extends "page.html" %} {% block body %} {% for collection in catalog %} {% +if collection %} +
+

+ {{ header }} + {{ collection }} +

+ {% for post in collection %} +
+

+ {% if fa %}{% endif %} {% if post.published %} {{ + post.date.strftime(ablog.post_date_format) }} {% else %} Draft {% endif %} + - + {{ post.title }} +

+ {% if 0 %} +
    + {% include "postcard2.html" %} +
+ {% endif %} +
+ {% endfor %} +
+{% endif %} {% endfor %} {% endblock %} diff --git a/ablog/templates/collection.html b/ablog/templates/collection.html index 405746dc..8c07b451 100644 --- a/ablog/templates/collection.html +++ b/ablog/templates/collection.html @@ -1,52 +1,52 @@ -{%- extends "page.html" %} {% block body %} -
-

- {% if archive_feed and fa %} - {% endif %} {{ header }} {% if collection.href %} - {{ collection }} - {% else %} {{ collection }} {% endif %} -

- {% if ablog.blog_archive_titles %} {% for post in collection %} -
-

- {% if fa %}{% endif %} {% if post.published %} {{ - post.date.strftime(ablog.post_date_format) }} {% else %} Draft {% endif %} - - - {{ post.title }} -

- {% if 0 %} -
    - {% include "postcard2.html" %} -
- {% endif %} -
- {% endfor %} {% else %} {% for post in collection %} - -
-

- {{ post.title }} -

- -
    -
  • - {% if post.published %} {% if fa %}{% - endif %} {{ post.date.strftime(ablog.post_date_format) }} {% else %} {% - if fa %}{% endif %} {% if post.date %}{{ - post.date.strftime(ablog.post_date_format) }} {% else %} Draft {% endif - %} {% endif %} -
  • - {% include "postcard2.html" %} -
- {{ post.to_html(collection.docname) }} -

{{ _("Read more ...") }}

-
-
- {% endfor %} {% endif %} -
-{% endblock %} +{%- extends "page.html" %} {% block body %} +
+

+ {% if archive_feed and fa %} + {% endif %} {{ header }} {% if collection.href %} + {{ collection }} + {% else %} {{ collection }} {% endif %} +

+ {% if ablog.blog_archive_titles %} {% for post in collection %} +
+

+ {% if fa %}{% endif %} {% if post.published %} {{ + post.date.strftime(ablog.post_date_format) }} {% else %} Draft {% endif %} + - + {{ post.title }} +

+ {% if 0 %} +
    + {% include "postcard2.html" %} +
+ {% endif %} +
+ {% endfor %} {% else %} {% for post in collection %} + +
+

+ {{ post.title }} +

+ +
    +
  • + {% if post.published %} {% if fa %}{% + endif %} {{ post.date.strftime(ablog.post_date_format) }} {% else %} {% + if fa %}{% endif %} {% if post.date %}{{ + post.date.strftime(ablog.post_date_format) }} {% else %} Draft {% endif + %} {% endif %} +
  • + {% include "postcard2.html" %} +
+ {{ post.to_html(collection.docname) }} +

{{ _("Read more ...") }}

+
+
+ {% endfor %} {% endif %} +
+{% endblock %} diff --git a/docs/make.bat b/docs/make.bat index 558ef605..d85ed391 100644 --- a/docs/make.bat +++ b/docs/make.bat @@ -1,35 +1,35 @@ -@ECHO OFF - -pushd %~dp0 - -REM Command file for Sphinx documentation - -if "%SPHINXBUILD%" == "" ( - set SPHINXBUILD=sphinx-build -) -set SOURCEDIR=. -set BUILDDIR=_build - -if "%1" == "" goto help - -%SPHINXBUILD% >NUL 2>NUL -if errorlevel 9009 ( - echo. - echo.The 'sphinx-build' command was not found. Make sure you have Sphinx - echo.installed, then set the SPHINXBUILD environment variable to point - echo.to the full path of the 'sphinx-build' executable. Alternatively you - echo.may add the Sphinx directory to PATH. - echo. - echo.If you don't have Sphinx installed, grab it from - echo.https://sphinx-doc.org/ - exit /b 1 -) - -%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% -goto end - -:help -%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% - -:end -popd +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=. +set BUILDDIR=_build + +if "%1" == "" goto help + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.https://sphinx-doc.org/ + exit /b 1 +) + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% + +:end +popd