Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dynamic date on blog pages #5801

Merged
merged 9 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ hack/__pycache__
/temp/
/temp-blog/
/blog/site/
/blog/overrides/
!/blog/overrides/
/blog/overrides/*
!/blog/overrides/partials/
/blog/overrides/partials/*
!/blog/overrides/partials/source-file.html
!/blog/overrides/partials/content.html
/blog/docs/stylesheets/
/node_modules/
venv/
Expand Down
5 changes: 5 additions & 0 deletions blog/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ plugins:
as_creation: "date"
as_update: false
datetime_format: "%Y-%m-%d"
git-revision-date-localized:
type: iso_date
enable_creation_date: true
exclude:
- index.md

copyright: "Copyright © 2022 The Knative Authors"

Expand Down
27 changes: 27 additions & 0 deletions blog/overrides/partials/content.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!-- based on https://github.com/squidfunk/mkdocs-material/blob/master/src/templates/partials/content.html -->

<style>
.md-typeset h1:nth-of-type(2),
.md-content__button:nth-of-type(2) {
display: none;
}
</style>


{% if page.toc %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally think this approach is okay for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where should I move the styling? Is it okay to create the new /overrides/assets/stylesheets/content.css file to avoid problems with docs website?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you think that's a good idea and can explain the reason why this change is worthy, why not? :))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think separating CSS from the HTML template is a good practice, as is separating CSS rules based on the files in which they act. For this reason, I will create the file /overrides/assets/stylesheets/content.css that is used only by the /overrides/partials/content.html file and doesn't interact with the docs website 😄 I will also remove the date from blog posts in which it is featured!

{% for toc_item in page.toc %}
<h1 id="TODO">
{{ toc_item.title }}
<a class="headerlink" href="{{ toc_item.url }}" title="Permanent link">¶</a>
</h1>
{% endfor %}
{% elif page.title %}
<h1>
{{ page.title }}
</h1>
{% endif %}

{% include "partials/source-file.html" %}

<!-- Page content -->
{{ page.content }}
14 changes: 14 additions & 0 deletions blog/overrides/partials/source-file.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% if page.meta.git_creation_date_localized and page.meta.git_revision_date_localized %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick suggestion: Let's only show 'Revised on' for posts that have been updated. If it's not edited since posting, we'll skip this part to keep things clear and simple. How does that sound?

<!-- Source file information -->
<!-- based on https://timvink.github.io/mkdocs-git-revision-date-localized-plugin/howto/override-a-theme -->

<p class="md-source-file">
<strong>
Published on:
{{ page.meta.git_creation_date_localized }}
,&nbsp;
Revised on:
{{ page.meta.git_revision_date_localized }}
</strong>
</p>
{% endif %}
2 changes: 1 addition & 1 deletion hack/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ fi

# Create the blog
# TODO copy templates, stylesheets, etc. into blog directory
cp -r overrides blog/
cp -rn overrides blog/
cp -r docs/images docs/stylesheets blog/docs/
pushd blog; mkdocs build -f mkdocs.yml -d "$SITE/blog"; popd

Expand Down
6 changes: 3 additions & 3 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ plugins:
search:
# Spaces, dashes, periods and forward-slash (so serving.knative.dev/blibble can be searched as blibble).
separator: '[\/\s\-\.]+'
macros:
module_name: hack/macros
include_dir: docs/snippets
exclude:
glob:
# Exclude files that contain hugo specific shortcodes
Expand All @@ -63,6 +60,9 @@ plugins:
filename: ".index"
collapse_single_pages: true
strict: false
macros:
module_name: hack/macros
include_dir: docs/snippets

copyright: "Copyright © 2022 The Knative Authors"

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ mkdocs-material<10.0
mkdocs-exclude>=1.0
mkdocs-macros-plugin>=0.5.12
mkdocs-awesome-pages-plugin>=2.5
mkdocs-git-revision-date-localized-plugin>=1.2
mkdocs-redirects>=1.0.3
mkdocs-rss-plugin>=0.18.0
pygithub==1.55
Expand Down
Loading