1
0
mirror of https://github.com/squidfunk/mkdocs-material.git synced 2025-02-06 14:14:23 +01:00

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( raise PluginError(
f"Couldn't find '{separator}' in post '{path}' in '{docs}'" 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 # Create excerpt for post and inherit authors and categories - excerpts
# can contain a subset of the authors and categories of the post # 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.authors: list[Author] = []
self.categories: list[Category] = [] 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, # Initialize parser - note that we need to patch the configuration,
# more specifically the table of contents extension # more specifically the table of contents extension
config = _patch(config) config = _patch(config)
@ -200,7 +204,9 @@ class Excerpt(Page):
# Convert Markdown to HTML and extract excerpt # Convert Markdown to HTML and extract excerpt
self.content = self.md.convert(self.markdown) 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 # 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 # the excerpt URL, linking to the excerpt from the view would not work

View File

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

View File

@ -271,8 +271,6 @@ class BlogPlugin(BasePlugin[BlogConfig]):
raise PluginError( raise PluginError(
f"Couldn't find '{separator}' in post '{path}' in '{docs}'" 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 # Create excerpt for post and inherit authors and categories - excerpts
# can contain a subset of the authors and categories of the post # 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.authors: list[Author] = []
self.categories: list[Category] = [] 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, # Initialize parser - note that we need to patch the configuration,
# more specifically the table of contents extension # more specifically the table of contents extension
config = _patch(config) config = _patch(config)
@ -200,7 +204,9 @@ class Excerpt(Page):
# Convert Markdown to HTML and extract excerpt # Convert Markdown to HTML and extract excerpt
self.content = self.md.convert(self.markdown) 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 # 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 # the excerpt URL, linking to the excerpt from the view would not work

View File

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