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
This commit is contained in:
Pete Bacon Darwin 2021-01-26 21:22:36 +00:00 committed by Misko Hevery
parent dceede4f80
commit d4f42b3223
4 changed files with 33 additions and 4 deletions

View File

@ -0,0 +1,6 @@
.reviewed {
color: lighten($darkgray, 10);
@include font-size(13);
font-style: italic;
text-align: right;
}

View File

@ -18,6 +18,7 @@
@import 'errors';
@import 'features';
@import 'filetree';
@import 'guides';
@import 'heading-anchors';
@import 'hr';
@import 'images';

View File

@ -0,0 +1,21 @@
/**
* @reviewed <date-string>
*
* 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),
};
}
};
};

View File

@ -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 %}
<div class="github-links">
<div class="github-links">
{$ github.githubEditLink(doc, versionInfo) $}
</div>
</div>
{% endif %}
{% block content %}
<div class="content">
{$ doc.description | marked $}
{$ doc.description | marked $}
{% if doc.reviewed %}<div class="reviewed">Last reviewed on {$ doc.reviewed.date.toDateString() $}</div>{% endif %}
</div>
{% endblock %}