From 3078eaa58c95b2c322cca97990bf07fbded48e0f Mon Sep 17 00:00:00 2001 From: Julien Date: Fri, 2 Oct 2020 16:34:38 +0200 Subject: [PATCH 01/17] Add webfeeds namespace --- mkdocs_rss_plugin/templates/rss.xml.jinja2 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mkdocs_rss_plugin/templates/rss.xml.jinja2 b/mkdocs_rss_plugin/templates/rss.xml.jinja2 index 69cbf471..e58fa7cf 100644 --- a/mkdocs_rss_plugin/templates/rss.xml.jinja2 +++ b/mkdocs_rss_plugin/templates/rss.xml.jinja2 @@ -1,7 +1,10 @@ + xmlns:dc="https://purl.org/dc/elements/1.1/" + xmlns:webfeeds=”http://webfeeds.org/rss/1.0″ + > + {{ feed.title }} From e147121bdf004e41c9ebb14062fe883b83c9d1ff Mon Sep 17 00:00:00 2001 From: Julien Date: Fri, 2 Oct 2020 16:35:04 +0200 Subject: [PATCH 02/17] First steps for date from meta --- mkdocs.yml | 3 +++ mkdocs_rss_plugin/plugin.py | 1 + 2 files changed, 4 insertions(+) diff --git a/mkdocs.yml b/mkdocs.yml index 1b78f8d2..3a24b3a4 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -15,6 +15,9 @@ plugins: - minify: minify_html: true - rss: + date_from_meta: + as_creation: "date" + as_update: false image: https://upload.wikimedia.org/wikipedia/commons/thumb/4/43/Feed-icon.svg/128px-Feed-icon.svg.png - search diff --git a/mkdocs_rss_plugin/plugin.py b/mkdocs_rss_plugin/plugin.py index 208be385..601049b2 100644 --- a/mkdocs_rss_plugin/plugin.py +++ b/mkdocs_rss_plugin/plugin.py @@ -40,6 +40,7 @@ class GitRssPlugin(BasePlugin): config_scheme = ( ("abstract_chars_count", config_options.Type(int, default=150)), ("category", config_options.Type(str, default=None)), + ("date_from_meta", config_options.Type(dict, default=None)), ("feed_ttl", config_options.Type(int, default=1440)), ("image", config_options.Type(str, default=None)), ("length", config_options.Type(int, default=20)), From 1b07cfca8b406e800fd27bfa19157af795ecc9b2 Mon Sep 17 00:00:00 2001 From: GeoJulien Date: Thu, 24 Dec 2020 16:21:52 +0100 Subject: [PATCH 03/17] Clean up --- mkdocs_rss_plugin/__about__.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mkdocs_rss_plugin/__about__.py b/mkdocs_rss_plugin/__about__.py index 665c0327..c93a54ca 100644 --- a/mkdocs_rss_plugin/__about__.py +++ b/mkdocs_rss_plugin/__about__.py @@ -20,7 +20,6 @@ "__author__", "__copyright__", "__email__", - "__executable_name__", "__license__", "__summary__", "__title__", @@ -33,9 +32,8 @@ __author__ = "Julien Moura" __copyright__ = "2020 - {0}, {1}".format(date.today().year, __author__) __email__ = "dev@ingeoveritas.com" -__executable_name__ = "MkDocsRssPlugin.exe" __license__ = "GNU General Public License v3.0" -__summary__ = "Generates a static RSS feed using git log." +__summary__ = "MkDocs plugin which generates a static RSS feed using git log." __title__ = "MkDocs RSS plugin" __title_clean__ = "".join(e for e in __title__ if e.isalnum()) __uri__ = "https://github.com/Guts/mkdocs-rss-plugin/" From a7ffb16fa99cdcbccb9dbdc7fd61665dfb36e2a7 Mon Sep 17 00:00:00 2001 From: GeoJulien Date: Thu, 24 Dec 2020 16:22:32 +0100 Subject: [PATCH 04/17] Add python 3.9 --- .github/workflows/lint-and-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint-and-tests.yml b/.github/workflows/lint-and-tests.yml index 56809b9c..718c5de1 100644 --- a/.github/workflows/lint-and-tests.yml +++ b/.github/workflows/lint-and-tests.yml @@ -20,7 +20,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.6, 3.7, 3.8] + python-version: [3.6, 3.7, 3.8, 3.9] # Steps represent a sequence of tasks that will be executed as part of the job steps: From a7fe886c8c1cfeff66244d8d0af5e3a409263374 Mon Sep 17 00:00:00 2001 From: GeoJulien Date: Thu, 24 Dec 2020 16:25:42 +0100 Subject: [PATCH 05/17] Revert "Add python 3.9" This reverts commit a7ffb16fa99cdcbccb9dbdc7fd61665dfb36e2a7. --- .github/workflows/lint-and-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lint-and-tests.yml b/.github/workflows/lint-and-tests.yml index 718c5de1..56809b9c 100644 --- a/.github/workflows/lint-and-tests.yml +++ b/.github/workflows/lint-and-tests.yml @@ -20,7 +20,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.6, 3.7, 3.8, 3.9] + python-version: [3.6, 3.7, 3.8] # Steps represent a sequence of tasks that will be executed as part of the job steps: From aa918cb9aafb671d89cb7f9d9e512959161a9774 Mon Sep 17 00:00:00 2001 From: GeoJulien Date: Thu, 24 Dec 2020 16:33:43 +0100 Subject: [PATCH 06/17] Add dates options to proper site --- mkdocs.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/mkdocs.yml b/mkdocs.yml index 3a24b3a4..d23b713d 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -18,6 +18,7 @@ plugins: date_from_meta: as_creation: "date" as_update: false + datetime_format: "%Y-%m-%d %H:%M" image: https://upload.wikimedia.org/wikipedia/commons/thumb/4/43/Feed-icon.svg/128px-Feed-icon.svg.png - search From 3f4ce321bbd8e632d9a2dbf224d9eb0836f9648f Mon Sep 17 00:00:00 2001 From: GeoJulien Date: Thu, 24 Dec 2020 16:33:52 +0100 Subject: [PATCH 07/17] Describe new options --- docs/configuration.md | 57 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) diff --git a/docs/configuration.md b/docs/configuration.md index f1d54e3f..d97e77c7 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -1,5 +1,6 @@ --- title: Configuration +date: 2020-12-31 14:20 description: Configuration steps and settings for MkDocs RSS plugin image: "https://svgsilh.com/png-512/97849.png" --- @@ -85,10 +86,64 @@ Output: ### Item description length -To fill each [item description element](https://www.w3schools.com/xml/rss_tag_title_link_description_item.asp), the plugin first tries to retrieve the value of the keyword `description` from the [page metadata](https://python-markdown.github.io/extensions/meta_data/). +To fill each [item description element](https://www.w3schools.com/xml/rss_tag_title_link_description_item.asp), the plugin first tries to retrieve the value of the keyword `description` from the [page metadata]. If the page has no meta, then the plugin retrieves the first number of characters of the page content defined by this setting. Retrieved content is raw markdown. `abstract_chars_count`: number of characters to use as item description. Default: `150` + +### Dates overriding + +Basically, the plugin aims to retrieve creation and update dates from git log. But sometimes, it does not match the content workflow as described in the following use cases. + +So, it's possible to use the dates manually specified into the [page metadata] through the [YAML frontmatter](https://www.mkdocs.org/user-guide/writing-your-docs/#meta-data). + +For example, in your pages, you can write the front-matter like this: + +```markdown +--- +title: "This page title is a perfect clickbait!" +authors: ["Julien M."] +date: "2020-12-28 10:20" +--- + +# This plugin will change your MkDocs life + +Lorem ipsum + +``` + +So in your `mkdocs.yml` you will have: + +```yaml +plugins: + - rss: + date_from_meta: + as_creation: "date" + as_update: false +``` + +#### Options + +`as_creation`: meta tag name to use as creation date. Default to False. +`as_update`: meta tag name to use as update date. Default to False. +`date_format`: datetime format. Default to "%Y-%m-%d %H:%M". + +If False, it will use th git log. + +#### Use cases + +##### Contribution and publication workflow + +- a writer create the article +- multiple authors will contribute to the article content +- after a few weeks, the article is published. But in the meantime, others articles have been published and trusting the git log it + +##### Generated pages from sources + +> TO DOC + + +[page metadata]: https://python-markdown.github.io/extensions/meta_data/ From b90b1e3b011efd32187e1b0a5ab486f7f3029247 Mon Sep 17 00:00:00 2001 From: GeoJulien Date: Thu, 24 Dec 2020 16:34:02 +0100 Subject: [PATCH 08/17] Handle new options --- mkdocs_rss_plugin/plugin.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/mkdocs_rss_plugin/plugin.py b/mkdocs_rss_plugin/plugin.py index 601049b2..0bf78965 100644 --- a/mkdocs_rss_plugin/plugin.py +++ b/mkdocs_rss_plugin/plugin.py @@ -32,10 +32,14 @@ OUTPUT_FEED_CREATED = "feed_rss_created.xml" OUTPUT_FEED_UPDATED = "feed_rss_updated.xml" +logger = logging.getLogger("mkdocs.mkdocs_rss_plugin") + # ############################################################################ # ########## Classes ############### # ################################## + + class GitRssPlugin(BasePlugin): config_scheme = ( ("abstract_chars_count", config_options.Type(int, default=150)), @@ -49,6 +53,9 @@ class GitRssPlugin(BasePlugin): def __init__(self): # tooling self.util = Util() + # dates source + self.src_date_created = self.src_date_updated = "git" + self.meta_datetime_format = None # pages storage self.pages_to_filter = [] # prepare output feeds @@ -96,6 +103,24 @@ def on_config(self, config: config_options.Config) -> dict: if self.config.get("image"): base_feed["logo_url"] = self.config.get("image") + # date handling + if self.config.get("date_from_meta") is not None: + self.src_date_created = self.config.get("date_from_meta").get( + "as_creation", False + ) + self.src_date_updated = self.config.get("date_from_meta").get( + "as_update", False + ) + self.meta_datetime_format = self.config.get("date_from_meta").get( + "datetime_format", "%Y-%m-%d %H:%M" + ) + logger.debug( + "[rss-plugin] Dates will be retrieved from page meta (yaml " + "frontmatter). The git log will be used as fallback." + ) + else: + logger.debug("[rss-plugin] Dates will be retrieved from git log.") + # create 2 final dicts self.feed_created = deepcopy(base_feed) self.feed_updated = deepcopy(base_feed) @@ -141,7 +166,12 @@ def on_page_markdown( str: Markdown source text of page as string """ # retrieve dates from git log - page_dates = self.util.get_file_dates(path=page.file.abs_src_path) + page_dates = self.util.get_file_dates( + in_page=page, + source_date_creation=self.src_date_created, + source_date_update=self.src_date_updated, + meta_datetime_format=self.meta_datetime_format + ) # append to list to be filtered later self.pages_to_filter.append( From ee793ded368896d112111c8496ff84056abdb66b Mon Sep 17 00:00:00 2001 From: GeoJulien Date: Thu, 24 Dec 2020 16:34:22 +0100 Subject: [PATCH 09/17] Use date from page meta if exists --- mkdocs_rss_plugin/util.py | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/mkdocs_rss_plugin/util.py b/mkdocs_rss_plugin/util.py index 8ad6dd69..d40cecb9 100644 --- a/mkdocs_rss_plugin/util.py +++ b/mkdocs_rss_plugin/util.py @@ -6,6 +6,7 @@ # standard library import logging +from datetime import datetime from email.utils import formatdate from mimetypes import guess_type from typing import Tuple @@ -21,6 +22,13 @@ from mkdocs_rss_plugin.git_manager.ci import CiHandler +# ############################################################################ +# ########## Globals ############### +# ################################## + +logger = logging.getLogger("mkdocs.mkdocs_rss_plugin") + + # ############################################################################ # ########## Classes ############# # ################################ @@ -67,10 +75,16 @@ def build_url(self, base_url: str, path: str, args_dict: dict = None) -> str: url_parts[4] = urlencode(args_dict) return urlunparse(url_parts) - def get_file_dates(self, path: str) -> Tuple[int, int]: + def get_file_dates( + self, + in_page: Page, + source_date_creation: str = "git", + source_date_update: str = "git", + meta_datetime_format: str = "%Y-%m-%d %H:%M" + ) -> Tuple[int, int]: """Extract creation and update dates from git log for given file. - :param str path: path to a tracked file + :param Page in_page: input page to work with :return: (creation date, last commit date) :rtype: tuple of timestamps @@ -78,14 +92,25 @@ def get_file_dates(self, path: str) -> Tuple[int, int]: # empty vars dt_created = dt_updated = None + if source_date_creation != "git" and in_page.meta.get(source_date_creation): + dt_created = in_page.meta.get(source_date_creation) + try: + dt_created = datetime.strptime(dt_created, meta_datetime_format) + except ValueError as err: + logger.error("Date in. Trace: {}".format(err)) + # explore git log if self.git_is_valid: try: dt_created = self.repo.log( - path, n=1, date="short", format="%at", diff_filter="AR" + in_page.file.abs_src_path, + n=1, + date="short", + format="%at", + diff_filter="AR", ) dt_updated = self.repo.log( - path, + in_page.file.abs_src_path, n=1, date="short", format="%at", @@ -94,7 +119,7 @@ def get_file_dates(self, path: str) -> Tuple[int, int]: logging.warning( "[rss-plugin] Unable to read git logs of '%s'. Is git log readable?" " Falling back to build date. " - " Trace: %s" % (path, err) + " Trace: %s" % (in_page.file.abs_src_path, err) ) except GitCommandNotFound as err: logging.error( From b12a2d513bd29106b59cc2958299df4d1f57948a Mon Sep 17 00:00:00 2001 From: GeoJulien Date: Thu, 24 Dec 2020 16:54:29 +0100 Subject: [PATCH 10/17] Fix undefined name --- mkdocs_rss_plugin/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mkdocs_rss_plugin/util.py b/mkdocs_rss_plugin/util.py index a43e7af4..2fccbb2c 100644 --- a/mkdocs_rss_plugin/util.py +++ b/mkdocs_rss_plugin/util.py @@ -154,7 +154,7 @@ def get_file_dates( int(dt_updated), ) else: - logging.warning("Dates could not be retrieved for page: %s." % path) + logging.warning("Dates could not be retrieved for page: %s." % in_page.file.abs_src_path) return ( get_build_timestamp(), get_build_timestamp(), From bb560efa57231d3d9e1faf721bc9fb11e31f9495 Mon Sep 17 00:00:00 2001 From: GeoJulien Date: Thu, 24 Dec 2020 17:20:07 +0100 Subject: [PATCH 11/17] fix tests --- tests/test_config.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_config.py b/tests/test_config.py index 5ed1f69b..bcb2aadf 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -57,6 +57,7 @@ def test_plugin_config_defaults(self): expected = { "abstract_chars_count": 150, "category": None, + "date_from_meta": None, "feed_ttl": 1440, "image": None, "length": 20, @@ -74,6 +75,7 @@ def test_plugin_config_image(self): expected = { "abstract_chars_count": 150, "category": None, + "date_from_meta": None, "feed_ttl": 1440, "image": self.feed_image, "length": 20, From 19eff921eb3a09adbfa4e79051e8ca1d87ea49ac Mon Sep 17 00:00:00 2001 From: GeoJulien Date: Thu, 24 Dec 2020 18:08:44 +0100 Subject: [PATCH 12/17] Improve theme config --- docs/conf.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index a19b302d..486f08f3 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -77,6 +77,21 @@ # a list of builtin themes. # html_theme = "sphinx_rtd_theme" +html_theme_options = { + # "canonical_url": __about__.__uri_homepage__, + "display_version": True, + "logo_only": False, + "prev_next_buttons_location": "both", + "style_external_links": True, + "style_nav_header_background": "SteelBlue", + # Toc options + "collapse_navigation": False, + "includehidden": False, + "navigation_depth": 4, + "sticky_navigation": False, + "titles_only": False, +} + html_sidebars = { "**": ["globaltoc.html", "relations.html", "sourcelink.html", "searchbox.html"] } @@ -84,7 +99,7 @@ # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ["_static"] +# html_static_path = ["_static"] # Configuration for intersphinx (refer to others docs). intersphinx_mapping = { From 4a601a23fa5205dab9244e6142737b3417d02a97 Mon Sep 17 00:00:00 2001 From: GeoJulien Date: Thu, 24 Dec 2020 18:12:55 +0100 Subject: [PATCH 13/17] Achieve logic --- mkdocs_rss_plugin/util.py | 76 +++++++++++++++++++++++++++------------ 1 file changed, 54 insertions(+), 22 deletions(-) diff --git a/mkdocs_rss_plugin/util.py b/mkdocs_rss_plugin/util.py index 2fccbb2c..3a5e4749 100644 --- a/mkdocs_rss_plugin/util.py +++ b/mkdocs_rss_plugin/util.py @@ -96,41 +96,70 @@ def get_file_dates( in_page: Page, source_date_creation: str = "git", source_date_update: str = "git", - meta_datetime_format: str = "%Y-%m-%d %H:%M" + meta_datetime_format: str = "%Y-%m-%d %H:%M", ) -> Tuple[int, int]: """Extract creation and update dates from git log for given file. - :param Page in_page: input page to work with - - :return: (creation date, last commit date) - :rtype: tuple of timestamps + :param in_page: input page to work with + :type in_page: Page + :param source_date_creation: which source to use (git or meta tag) for creation \ + date, defaults to "git" + :type source_date_creation: str, optional + :param source_date_update: which source to use (git or meta tag) for update \ + date, defaults to "git" + :type source_date_update: str, optional + :param meta_datetime_format: datetime string format, defaults to "%Y-%m-%d %H:%M" + :type meta_datetime_format: str, optional + + :return: tuple of timestamps (creation date, last commit date) + :rtype: Tuple[int, int] """ # empty vars dt_created = dt_updated = None + # if enabled, try to retrieve dates from page metadata if source_date_creation != "git" and in_page.meta.get(source_date_creation): - dt_created = in_page.meta.get(source_date_creation) try: - dt_created = datetime.strptime(dt_created, meta_datetime_format) + dt_created = datetime.strptime( + in_page.meta.get(source_date_creation), meta_datetime_format + ).timestamp() except ValueError as err: - logger.error("Date in. Trace: {}".format(err)) + logger.error( + "[rss-plugin] Incompatible date found in meta of page: {}. Trace: {}".format( + in_page.file.abs_src_path, err + ) + ) + if source_date_update != "git" and in_page.meta.get(source_date_update): + try: + dt_updated = datetime.strptime( + in_page.meta.get(source_date_update), meta_datetime_format + ).timestamp() + except ValueError as err: + logger.error( + "[rss-plugin] Incompatible date found in meta of page: {}. Trace: {}".format( + in_page.file.abs_src_path, err + ) + ) # explore git log if self.git_is_valid: try: - dt_created = self.repo.log( - in_page.file.abs_src_path, - n=1, - date="short", - format="%at", - diff_filter="AR", - ) - dt_updated = self.repo.log( - in_page.file.abs_src_path, - n=1, - date="short", - format="%at", - ) + # only if dates have not been retrieved from page meta + if not dt_created: + dt_created = self.repo.log( + in_page.file.abs_src_path, + n=1, + date="short", + format="%at", + diff_filter="AR", + ) + if not dt_updated: + dt_updated = self.repo.log( + in_page.file.abs_src_path, + n=1, + date="short", + format="%at", + ) except GitCommandError as err: logging.warning( "[rss-plugin] Unable to read git logs of '%s'. Is git log readable?" @@ -154,7 +183,10 @@ def get_file_dates( int(dt_updated), ) else: - logging.warning("Dates could not be retrieved for page: %s." % in_page.file.abs_src_path) + logging.warning( + "[rss-plugin] Dates could not be retrieved for page: %s." + % in_page.file.abs_src_path + ) return ( get_build_timestamp(), get_build_timestamp(), From 3d48dd59ebd26568a1d203e2eb907a30d592b461 Mon Sep 17 00:00:00 2001 From: GeoJulien Date: Thu, 24 Dec 2020 18:17:11 +0100 Subject: [PATCH 14/17] Bump pre-commit hooks --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 503b4f3f..24921c5f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,7 +4,7 @@ exclude: "node_modules|migrations|.venv|tests/dev/|tests/fixtures/" fail_fast: false repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v3.3.0 + rev: v3.4.0 hooks: - id: check-added-large-files args: ['--maxkb=500'] From bc46d7779aad9fca6467bbe0492d75cfef752db8 Mon Sep 17 00:00:00 2001 From: GeoJulien Date: Thu, 24 Dec 2020 18:17:30 +0100 Subject: [PATCH 15/17] Add typical plugin config --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index 700f5674..acd5dfe1 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,21 @@ A plugin for [MkDocs](https://www.mkdocs.org), the static site generator, which ## Usage +Typical `mkdocs.yml`: + +```yaml +plugins: + - rss: + abstract_chars_count: 160 + feed_ttl: 1440 + length: 20 + date_from_meta: + as_creation: "date" + as_update: false + datetime_format: "%Y-%m-%d %H:%M" + image: https://upload.wikimedia.org/wikipedia/commons/thumb/4/43/Feed-icon.svg/128px-Feed-icon.svg.png +``` + For further information, [see the user documentation](https://guts.github.io/mkdocs-rss-plugin/). ## Development From 0c7b8326dd9ace4b3eb09a255f533817d6114a1d Mon Sep 17 00:00:00 2001 From: GeoJulien Date: Thu, 24 Dec 2020 18:18:05 +0100 Subject: [PATCH 16/17] Switch default to 160 (max recomended SEO length) --- mkdocs_rss_plugin/plugin.py | 4 ++-- tests/test_config.py | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/mkdocs_rss_plugin/plugin.py b/mkdocs_rss_plugin/plugin.py index 9ba8281b..c777b22a 100644 --- a/mkdocs_rss_plugin/plugin.py +++ b/mkdocs_rss_plugin/plugin.py @@ -42,7 +42,7 @@ class GitRssPlugin(BasePlugin): config_scheme = ( - ("abstract_chars_count", config_options.Type(int, default=150)), + ("abstract_chars_count", config_options.Type(int, default=160)), ("category", config_options.Type(str, default=None)), ("date_from_meta", config_options.Type(dict, default=None)), ("feed_ttl", config_options.Type(int, default=1440)), @@ -169,7 +169,7 @@ def on_page_markdown( in_page=page, source_date_creation=self.src_date_created, source_date_update=self.src_date_updated, - meta_datetime_format=self.meta_datetime_format + meta_datetime_format=self.meta_datetime_format, ) # append to list to be filtered later diff --git a/tests/test_config.py b/tests/test_config.py index bcb2aadf..cb73b411 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -14,7 +14,6 @@ # ################################## # Standard library -import logging import unittest from pathlib import Path @@ -55,7 +54,7 @@ def tearDownClass(cls): def test_plugin_config_defaults(self): # default reference expected = { - "abstract_chars_count": 150, + "abstract_chars_count": 160, "category": None, "date_from_meta": None, "feed_ttl": 1440, @@ -73,7 +72,7 @@ def test_plugin_config_defaults(self): def test_plugin_config_image(self): # reference expected = { - "abstract_chars_count": 150, + "abstract_chars_count": 160, "category": None, "date_from_meta": None, "feed_ttl": 1440, From b758e116b2eb44325b811ac30af9c88fb5f762cf Mon Sep 17 00:00:00 2001 From: GeoJulien Date: Thu, 24 Dec 2020 18:25:10 +0100 Subject: [PATCH 17/17] Complete doc about new feature --- docs/usage/configuration.md | 43 +++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/docs/usage/configuration.md b/docs/usage/configuration.md index ed36e00c..cce2e589 100644 --- a/docs/usage/configuration.md +++ b/docs/usage/configuration.md @@ -111,23 +111,28 @@ Default: `150` ### Dates overriding -Basically, the plugin aims to retrieve creation and update dates from git log. But sometimes, it does not match the content workflow as described in the following use cases. +Basically, the plugin aims to retrieve creation and update dates from git log. But sometimes, it does not match the content workflow: markdown generated from sources, . So, it's possible to use the dates manually specified into the [page metadata] through the [YAML frontmatter](https://www.mkdocs.org/user-guide/writing-your-docs/#meta-data). -For example, in your pages, you can write the front-matter like this: +- `as_creation`: meta tag name to use as creation date. Default to False. +- `as_update`: meta tag name to use as update date. Default to False. +- `datetime_format`: datetime format. Default to "%Y-%m-%d %H:%M". + +#### Example + +For example, in your `best_article.md` created in 2019, you can write the front-matter like this: ```markdown --- title: "This page title is a perfect clickbait!" authors: ["Julien M."] -date: "2020-12-28 10:20" +date: "2020-10-22 17:18" --- # This plugin will change your MkDocs life -Lorem ipsum - +Lorem ipsum [...] ``` So in your `mkdocs.yml` you will have: @@ -138,28 +143,20 @@ plugins: date_from_meta: as_creation: "date" as_update: false + datetime_format: "%Y-%m-%d %H:%M" ``` -#### Options - -`as_creation`: meta tag name to use as creation date. Default to False. -`as_update`: meta tag name to use as update date. Default to False. -`date_format`: datetime format. Default to "%Y-%m-%d %H:%M". - -If False, it will use th git log. - -#### Use cases +At the end, into the RSS you will get: -##### Contribution and publication workflow - -- a writer create the article -- multiple authors will contribute to the article content -- after a few weeks, the article is published. But in the meantime, others articles have been published and trusting the git log it - -##### Generated pages from sources - -> TO DOC +```xml + + This page title is a perfect clickbait! + https://website.com/articles/best_article/ + Thu, 22 Oct 2020 17:18:00 -0000 + [...] + +``` ----