Skip to content

Commit b7fc7ba

Browse files
committed
Removed continue reading link when there's nothing more to read
1 parent 55603a7 commit b7fc7ba

File tree

6 files changed

+28
-16
lines changed

6 files changed

+28
-16
lines changed

material/plugins/blog/plugin.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,6 @@ def on_page_markdown(self, markdown, *, page, config, files):
271271
raise PluginError(
272272
f"Couldn't find '{separator}' in post '{path}' in '{docs}'"
273273
)
274-
else:
275-
page.markdown += f"\n\n{separator}"
276274

277275
# Create excerpt for post and inherit authors and categories - excerpts
278276
# can contain a subset of the authors and categories of the post

material/plugins/blog/structure/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ def __init__(self, post: Post, config: MkDocsConfig, files: Files):
156156
self.authors: list[Author] = []
157157
self.categories: list[Category] = []
158158

159+
# Initialize content after separator - allow template authors to render
160+
# posts inline or to provide a link to the post's page
161+
self.more = None
162+
159163
# Initialize parser - note that we need to patch the configuration,
160164
# more specifically the table of contents extension
161165
config = _patch(config)
@@ -200,7 +204,9 @@ def render(self, page: Page, separator: str):
200204

201205
# Convert Markdown to HTML and extract excerpt
202206
self.content = self.md.convert(self.markdown)
203-
self.content, *_ = self.content.split(separator, 1)
207+
self.content, *more = self.content.split(separator, 1)
208+
if more:
209+
self.more = more[0]
204210

205211
# Extract table of contents and reset post URL - if we wouldn't reset
206212
# the excerpt URL, linking to the excerpt from the view would not work

material/templates/partials/post.html

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,12 @@
5151
</header>
5252
<div class="md-post__content md-typeset">
5353
{{ post.content }}
54-
<nav class="md-post__action">
55-
<a href="{{ post.url | url }}">
56-
{{ lang.t("blog.continue") }}
57-
</a>
58-
</nav>
54+
{% if post.more %}
55+
<nav class="md-post__action">
56+
<a href="{{ post.url | url }}">
57+
{{ lang.t("blog.continue") }}
58+
</a>
59+
</nav>
60+
{% endif %}
5961
</div>
6062
</article>

src/plugins/blog/plugin.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,6 @@ def on_page_markdown(self, markdown, *, page, config, files):
271271
raise PluginError(
272272
f"Couldn't find '{separator}' in post '{path}' in '{docs}'"
273273
)
274-
else:
275-
page.markdown += f"\n\n{separator}"
276274

277275
# Create excerpt for post and inherit authors and categories - excerpts
278276
# can contain a subset of the authors and categories of the post

src/plugins/blog/structure/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,10 @@ def __init__(self, post: Post, config: MkDocsConfig, files: Files):
156156
self.authors: list[Author] = []
157157
self.categories: list[Category] = []
158158

159+
# Initialize content after separator - allow template authors to render
160+
# posts inline or to provide a link to the post's page
161+
self.more = None
162+
159163
# Initialize parser - note that we need to patch the configuration,
160164
# more specifically the table of contents extension
161165
config = _patch(config)
@@ -200,7 +204,9 @@ def render(self, page: Page, separator: str):
200204

201205
# Convert Markdown to HTML and extract excerpt
202206
self.content = self.md.convert(self.markdown)
203-
self.content, *_ = self.content.split(separator, 1)
207+
self.content, *more = self.content.split(separator, 1)
208+
if more:
209+
self.more = more[0]
204210

205211
# Extract table of contents and reset post URL - if we wouldn't reset
206212
# the excerpt URL, linking to the excerpt from the view would not work

src/templates/partials/post.html

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,12 @@
9090
{{ post.content }}
9191

9292
<!-- Continue reading link -->
93-
<nav class="md-post__action">
94-
<a href="{{ post.url | url }}">
95-
{{ lang.t("blog.continue") }}
96-
</a>
97-
</nav>
93+
{% if post.more %}
94+
<nav class="md-post__action">
95+
<a href="{{ post.url | url }}">
96+
{{ lang.t("blog.continue") }}
97+
</a>
98+
</nav>
99+
{% endif %}
98100
</div>
99101
</article>

0 commit comments

Comments
 (0)