From d4f42b3223729955122bf168e7fb3e493690d6b4 Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Tue, 26 Jan 2021 21:22:36 +0000 Subject: [PATCH] build(docs-infra): implement `@reviewed` tag definition (#40582) The `@reviewed` tag can be used to specify the date when the document was last reviewed. PR Close #40582 --- aio/src/styles/2-modules/_guides.scss | 6 ++++++ aio/src/styles/2-modules/_modules-dir.scss | 1 + .../content-package/tag-defs/reviewed.js | 21 +++++++++++++++++++ .../templates/content.template.html | 9 ++++---- 4 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 aio/src/styles/2-modules/_guides.scss create mode 100644 aio/tools/transforms/content-package/tag-defs/reviewed.js diff --git a/aio/src/styles/2-modules/_guides.scss b/aio/src/styles/2-modules/_guides.scss new file mode 100644 index 0000000000..db656ac923 --- /dev/null +++ b/aio/src/styles/2-modules/_guides.scss @@ -0,0 +1,6 @@ +.reviewed { + color: lighten($darkgray, 10); + @include font-size(13); + font-style: italic; + text-align: right; +} \ No newline at end of file diff --git a/aio/src/styles/2-modules/_modules-dir.scss b/aio/src/styles/2-modules/_modules-dir.scss index d55755d566..1c48725103 100644 --- a/aio/src/styles/2-modules/_modules-dir.scss +++ b/aio/src/styles/2-modules/_modules-dir.scss @@ -18,6 +18,7 @@ @import 'errors'; @import 'features'; @import 'filetree'; + @import 'guides'; @import 'heading-anchors'; @import 'hr'; @import 'images'; diff --git a/aio/tools/transforms/content-package/tag-defs/reviewed.js b/aio/tools/transforms/content-package/tag-defs/reviewed.js new file mode 100644 index 0000000000..bcbe6bd18c --- /dev/null +++ b/aio/tools/transforms/content-package/tag-defs/reviewed.js @@ -0,0 +1,21 @@ +/** + * @reviewed + * + * Use this tag-def to indicate the date when this document was last reviewed. + * The date-string will be passed to the `Date()` constructor. + */ +module.exports = function(createDocMessage) { + return { + name: 'reviewed', + transforms(doc, tag, value) { + if (!/^\d{4}-\d{1,2}-\d{1,2}/.test(value.trim())) { + throw new Error(createDocMessage( + `Tag Error: @${tag.tagName} tag is missing the required date in the form "yyyy-mm-dd" but got "${value}"\n`, + doc)); + } + return { + date: new Date(value), + }; + } + }; +}; diff --git a/aio/tools/transforms/templates/content.template.html b/aio/tools/transforms/templates/content.template.html index 58d0baf52d..81c975493c 100644 --- a/aio/tools/transforms/templates/content.template.html +++ b/aio/tools/transforms/templates/content.template.html @@ -3,12 +3,13 @@ {% set relativePath = doc.fileInfo.relativePath %} {% if doc.title %}{$ ('# ' + doc.title.trim()) | marked $}{% endif %} {% if '/' in relativePath or 'docs.md' in relativePath %} - + {% endif %} {% block content %}
-{$ doc.description | marked $} + {$ doc.description | marked $} + {% if doc.reviewed %}
Last reviewed on {$ doc.reviewed.date.toDateString() $}
{% endif %}
{% endblock %} \ No newline at end of file