Removed continue reading link when there's nothing more to read

This commit is contained in:
squidfunk 2024-02-15 12:07:47 +07:00
parent 55603a70e8
commit b7fc7bad5e
No known key found for this signature in database
GPG Key ID: 5ED40BC4F9C436DF
6 changed files with 28 additions and 16 deletions

View File

@ -271,8 +271,6 @@ class BlogPlugin(BasePlugin[BlogConfig]):
raise PluginError(
f"Couldn't find '{separator}' in post '{path}' in '{docs}'"
)
else:
page.markdown += f"\n\n{separator}"
# Create excerpt for post and inherit authors and categories - excerpts
# can contain a subset of the authors and categories of the post

View File

@ -156,6 +156,10 @@ class Excerpt(Page):
self.authors: list[Author] = []
self.categories: list[Category] = []
# Initialize content after separator - allow template authors to render
# posts inline or to provide a link to the post's page
self.more = None
# Initialize parser - note that we need to patch the configuration,
# more specifically the table of contents extension
config = _patch(config)
@ -200,7 +204,9 @@ class Excerpt(Page):
# Convert Markdown to HTML and extract excerpt
self.content = self.md.convert(self.markdown)
self.content, *_ = self.content.split(separator, 1)
self.content, *more = self.content.split(separator, 1)
if more:
self.more = more[0]
# Extract table of contents and reset post URL - if we wouldn't reset
# the excerpt URL, linking to the excerpt from the view would not work

View File

@ -51,10 +51,12 @@
</header>
<div class="md-post__content md-typeset">
{{ post.content }}
<nav class="md-post__action">
<a href="{{ post.url | url }}">
{{ lang.t("blog.continue") }}
</a>
</nav>
{% if post.more %}
<nav class="md-post__action">
<a href="{{ post.url | url }}">
{{ lang.t("blog.continue") }}
</a>
</nav>
{% endif %}
</div>
</article>

View File

@ -271,8 +271,6 @@ class BlogPlugin(BasePlugin[BlogConfig]):
raise PluginError(
f"Couldn't find '{separator}' in post '{path}' in '{docs}'"
)
else:
page.markdown += f"\n\n{separator}"
# Create excerpt for post and inherit authors and categories - excerpts
# can contain a subset of the authors and categories of the post

View File

@ -156,6 +156,10 @@ class Excerpt(Page):
self.authors: list[Author] = []
self.categories: list[Category] = []
# Initialize content after separator - allow template authors to render
# posts inline or to provide a link to the post's page
self.more = None
# Initialize parser - note that we need to patch the configuration,
# more specifically the table of contents extension
config = _patch(config)
@ -200,7 +204,9 @@ class Excerpt(Page):
# Convert Markdown to HTML and extract excerpt
self.content = self.md.convert(self.markdown)
self.content, *_ = self.content.split(separator, 1)
self.content, *more = self.content.split(separator, 1)
if more:
self.more = more[0]
# Extract table of contents and reset post URL - if we wouldn't reset
# the excerpt URL, linking to the excerpt from the view would not work

View File

@ -90,10 +90,12 @@
{{ post.content }}
<!-- Continue reading link -->
<nav class="md-post__action">
<a href="{{ post.url | url }}">
{{ lang.t("blog.continue") }}
</a>
</nav>
{% if post.more %}
<nav class="md-post__action">
<a href="{{ post.url | url }}">
{{ lang.t("blog.continue") }}
</a>
</nav>
{% endif %}
</div>
</article>