Skip to content

Commit

Permalink
Adding effectiveDate frontmatter property (github#22317)
Browse files Browse the repository at this point in the history
* adding effectiveDate frontmatter property

* Update components/article/ArticlePage.tsx

Co-authored-by: Peter Bengtsson <peterbe@github.com>

* adding validation for correct date

* update to dateTime

* update to year month day

* update error date validation

* moving validation to getArticleContextFromRequest and moving id to div

* remove enteredDate

* Update content/README.md

Co-authored-by: Laura Coursen <lecoursen@github.com>

Co-authored-by: Peter Bengtsson <peterbe@github.com>
Co-authored-by: Laura Coursen <lecoursen@github.com>
  • Loading branch information
3 people committed Oct 20, 2021
1 parent f849891 commit 884556e
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 0 deletions.
9 changes: 9 additions & 0 deletions components/article/ArticlePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const ArticlePage = () => {
const {
title,
intro,
effectiveDate,
renderedPage,
contributor,
permissions,
Expand Down Expand Up @@ -153,6 +154,14 @@ export const ArticlePage = () => {
>
<div id="article-contents">
<MarkdownContent>{renderedPage}</MarkdownContent>
{effectiveDate && (
<div className="mt-4" id="effectiveDate">
Effective as of:{' '}
<time dateTime={new Date(effectiveDate).toISOString()}>
{new Date(effectiveDate).toDateString()}
</time>
</div>
)}
</div>
</ArticleGridLayout>

Expand Down
11 changes: 11 additions & 0 deletions components/context/ArticleContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export type MiniTocItem = {
export type ArticleContextT = {
title: string
intro: string
effectiveDate: string
renderedPage: string
miniTocItems: Array<MiniTocItem>
contributor: { name: string; URL: string } | null
Expand All @@ -40,9 +41,19 @@ export const useArticleContext = (): ArticleContextT => {

export const getArticleContextFromRequest = (req: any): ArticleContextT => {
const page = req.context.page

if (page.effectiveDate) {
if (isNaN(Date.parse(page.effectiveDate))) {
throw new Error(
'The "effectiveDate" frontmatter property is not valid. Please make sure it is YEAR-MONTH-DAY'
)
}
}

return {
title: page.titlePlainText,
intro: page.intro,
effectiveDate: page.effectiveDate || '',
renderedPage: req.context.renderedPage || '',
miniTocItems: req.context.miniTocItems || [],
contributor: page.contributor || null,
Expand Down
6 changes: 6 additions & 0 deletions content/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ See the [contributing docs](/CONTRIBUTING.md) for general information about work
- [`topics`](#topics)
- [`contributor`](#contributor)
- [`communityRedirect`](#communityRedirect)
- [`effectiveDate`](#effectiveDate)
- [Escaping single quotes](#escaping-single-quotes)
- [Autogenerated mini TOCs](#autogenerated-mini-tocs)
- [Versioning](#versioning)
Expand Down Expand Up @@ -270,6 +271,11 @@ includeGuides:
- Type: `Object`. Properties are `name` and `href`.
- Optional.

### `effectiveDate`
- **For GitHub staff only**: Set an effective date for Terms of Service articles so that engineering teams can automatically re-prompt users to confirm the terms
- Type: `string` YEAR-MONTH-DAY e.g. 2021-10-04 is October 4th, 2021
- Optional.

Example:

```yaml
Expand Down
1 change: 1 addition & 0 deletions content/github/copilot/github-copilot-telemetry-terms.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ redirect_from:
- /github/copilot/telemetry-terms
versions:
fpt: '*'
effectiveDate: '2021-10-04'
---

## Additional telemetry
Expand Down
3 changes: 3 additions & 0 deletions lib/frontmatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ export const schema = {
examples_source: {
type: 'string',
},
effectiveDate: {
type: 'string',
},
featuredLinks: {
type: 'object',
properties: {
Expand Down
6 changes: 6 additions & 0 deletions middleware/render-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ export default async function renderPage(req, res, next) {
// add page context
const context = Object.assign({}, req.context, { page })

// Updating the Last-Modified header for substantive changes on a page for engineering
// Docs Engineering Issue #945
if (context.page.effectiveDate !== '') {
res.setHeader('Last-Modified', new Date(context.page.effectiveDate).toUTCString())
}

// collect URLs for variants of this page in all languages
context.page.languageVariants = Page.getLanguageVariants(req.pagePath)
// Stop processing if the connection was already dropped
Expand Down

0 comments on commit 884556e

Please sign in to comment.