Skip to content

Commit 934017c

Browse files
committed
split up back to config and builder parts
1 parent 5fb799c commit 934017c

1 file changed

Lines changed: 16 additions & 14 deletions

File tree

ablog/__init__.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,24 @@ def html_page_context(app, pagename, templatename, context, doctree):
7272
context["feed_title"] = blog.blog_title
7373

7474

75+
def config_inited(app):
76+
# Automatically identify any blog posts if a pattern is specified in the config
77+
if isinstance(app.config.blog_post_pattern, str):
78+
app.config.blog_post_pattern = [app.config.blog_post_pattern]
79+
matched_patterns = []
80+
for pattern in app.config.blog_post_pattern:
81+
pattern = os.path.join(app.srcdir, pattern)
82+
# make sure that blog post paths have forward slashes even on windows
83+
matched_patterns.extend(
84+
PurePath(ii).relative_to(app.srcdir).with_suffix("").as_posix()
85+
for ii in glob(pattern, recursive=True)
86+
)
87+
app.config.matched_blog_posts = matched_patterns
88+
89+
7590
def builder_inited(app):
7691
if app.config.skip_injecting_base_ablog_templates:
7792
return
78-
7993
if not isinstance(app.builder.templates, BuiltinTemplateLoader):
8094
raise Exception(
8195
"Ablog does not know how to inject templates into with custom "
@@ -106,19 +120,6 @@ def builder_inited(app):
106120
# that don't support it out-of-the-box, like alabaster.
107121
loaders.insert(templatepathlen, SphinxFileSystemLoader(get_html_templates_path()))
108122

109-
# Automatically identify any blog posts if a pattern is specified in the config
110-
if isinstance(app.config.blog_post_pattern, str):
111-
app.config.blog_post_pattern = [app.config.blog_post_pattern]
112-
matched_patterns = []
113-
for pattern in app.config.blog_post_pattern:
114-
pattern = os.path.join(app.srcdir, pattern)
115-
# make sure that blog post paths have forward slashes even on windows
116-
matched_patterns.extend(
117-
PurePath(ii).relative_to(app.srcdir).with_suffix("").as_posix()
118-
for ii in glob(pattern, recursive=True)
119-
)
120-
app.config.matched_blog_posts = matched_patterns
121-
122123

123124
def setup(app):
124125
"""
@@ -128,6 +129,7 @@ def setup(app):
128129
app.add_config_value(*args[:3])
129130
app.add_directive("post", PostDirective)
130131
app.add_directive("postlist", PostListDirective)
132+
app.connect("config-inited", config_inited)
131133
app.connect("builder-inited", builder_inited)
132134
app.connect("doctree-read", process_posts)
133135
app.connect("env-purge-doc", purge_posts)

0 commit comments

Comments
 (0)