Skip to content

Commit

Permalink
Removed continue reading link when there's nothing more to read
Browse files Browse the repository at this point in the history
  • Loading branch information
squidfunk committed Feb 15, 2024
1 parent 55603a7 commit b7fc7ba
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 16 deletions.
2 changes: 0 additions & 2 deletions material/plugins/blog/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,6 @@ def on_page_markdown(self, markdown, *, page, config, files):
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
Expand Down
8 changes: 7 additions & 1 deletion material/plugins/blog/structure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ def __init__(self, post: Post, config: MkDocsConfig, files: Files):
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)
Expand Down Expand Up @@ -200,7 +204,9 @@ def render(self, page: Page, separator: str):

# 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
Expand Down
12 changes: 7 additions & 5 deletions material/templates/partials/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
2 changes: 0 additions & 2 deletions src/plugins/blog/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,6 @@ def on_page_markdown(self, markdown, *, page, config, files):
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
Expand Down
8 changes: 7 additions & 1 deletion src/plugins/blog/structure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ def __init__(self, post: Post, config: MkDocsConfig, files: Files):
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)
Expand Down Expand Up @@ -200,7 +204,9 @@ def render(self, page: Page, separator: str):

# 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
Expand Down
12 changes: 7 additions & 5 deletions src/templates/partials/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>

0 comments on commit b7fc7ba

Please sign in to comment.