Skip to content

Commit

Permalink
Populate product-landing "What's new" section using GitHub Changelog (g…
Browse files Browse the repository at this point in the history
…ithub#18328)

Co-authored-by: Jason Etcovitch <[email protected]>
Co-authored-by: Rachael Sewell <[email protected]>
Co-authored-by: Sarah Schneider <[email protected]>
  • Loading branch information
4 people authored Apr 8, 2021
1 parent 9b3eb7d commit bbd9f03
Show file tree
Hide file tree
Showing 43 changed files with 292 additions and 320 deletions.
8 changes: 5 additions & 3 deletions content/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,10 @@ featuredLinks:

### `changelog`

- Purpose: Render a list of changelog items with timestamps on product pages (ex: `layouts/product-landing.html`)
- Type: `Array`, items are objects `{ href: string, title: string, date: 'YYYY-MM-DD' }`
- Purpose: Render a list of items pulled from [GitHub Changelog](https://github.blog/changelog/) on product landing pages (ex: `layouts/product-landing.html`). The one exception is Education, which pulls from https://github.blog/category/community/education.
- Type: `Object`, properties:
- `label` -- must be present and corresponds to the labels used in the [GitHub Changelog](https://github.blog/changelog/)
- `prefix` -- optional string that starts each changelog title that should be omitted in the docs feed. For example, with the prefix `GitHub Actions: ` specified, changelog titles like `GitHub Actions: Some Title Here` will render as `Some Title Here` in the docs feed).
- Optional.

### `defaultPlatform`
Expand Down Expand Up @@ -223,7 +225,7 @@ includeGuides:
```

### `type`
- Purpose: Indicate the type of article.
- Purpose: Indicate the type of article.
- Type: `String`, one of the `overview`, `quick_start`, `tutorial`, `how_to`, `reference`.
- Optional.

Expand Down
13 changes: 2 additions & 11 deletions content/actions/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,9 @@ featuredLinks:
- /actions/reference/environment-variables
- /actions/reference/encrypted-secrets
changelog:
- title: Environments, environment protection rules and environment secrets (beta)
date: '2020-12-15'
href: https://github.blog/changelog/2020-12-15-github-actions-environments-environment-protection-rules-and-environment-secrets-beta/
- title: Workflow visualization
date: '2020-12-08'
href: https://github.blog/changelog/2020-12-08-github-actions-workflow-visualization/
- title: Removing set-env and add-path commands on November 16
date: '2020-11-09'
href: https://github.blog/changelog/2020-10-01-github-actions-deprecating-set-env-and-add-path-commands/

label: 'actions'
prefix: 'GitHub Actions: '
product_video: https://www.youtube-nocookie.com/embed/cP0I9w2coGU

redirect_from:
- /articles/automating-your-workflow-with-github-actions/
- /articles/customizing-your-project-with-github-actions/
Expand Down
2 changes: 2 additions & 0 deletions content/discussions/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ featuredLinks:
- /discussions/guides/finding-discussions-across-multiple-repositories
- /discussions/collaborating-with-your-community-using-discussions/collaborating-with-maintainers-using-discussions
- /discussions/managing-discussions-for-your-community/managing-categories-for-discussions-in-your-repository
changelog:
label: 'discussions'
product_video: https://www.youtube-nocookie.com/embed/IpBw2SJkFyk
layout: product-landing
versions:
Expand Down
15 changes: 1 addition & 14 deletions content/education/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,8 @@ featuredLinks:
- /desktop
- /github/getting-started-with-github/github-cli
- /education/manage-coursework-with-github-classroom/teach-with-github-classroom

changelog:
- title: 'Try something new at Local Hack Day: Learn'
date: '2020-10-15'
href: https://github.blog/2020-10-15-try-something-new-at-local-hack-day-learn/
- title: 'Remote Education: Creating community through shared experiences'
date: '2020-09-24'
href: https://github.blog/2020-09-24-remote-education-creating-community-through-shared-experiences/
- title: 'Remote Education: A series of best practices for online campus communities'
date: '2020-09-10'
href: https://github.blog/2020-09-10-remote-education-a-series-of-best-practices-for-online-campus-communities/
- title: Welcome to the inaugural class of MLH Fellows
date: '2020-06-24'
href: https://github.blog/2020-06-24-welcome-to-the-inaugural-class-of-mlh-fellows/

label: 'education'
layout: product-landing
versions:
free-pro-team: '*'
Expand Down
11 changes: 2 additions & 9 deletions content/packages/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,8 @@ featuredLinks:
- /packages/guides/enabling-improved-container-support
- /packages/guides/configuring-rubygems-for-use-with-github-packages
changelog:
- title: ghcr.io maintenance mode on 2021-01-09
date: '2021-01-08'
href: https://github.blog/changelog/2021-01-08-packages-ghcr-io-maintenance-mode-on-2021-01-09/
- title: ghcr.io container names redirect to the container page
date: '2020-12-14'
href: https://github.blog/changelog/2020-12-14-ghcr-io-container-names-redirect-to-the-container-page/
- title: Filter for tagged and untagged containers
date: '2020-12-14'
href: https://github.blog/changelog/2020-12-14-packages-can-filter-for-tagged-and-untagged-containers/
label: 'packages'
prefix: 'Packages: '
redirect_from:
- /github/managing-packages-with-github-packages
- /categories/managing-packages-with-github-package-registry
Expand Down
6 changes: 3 additions & 3 deletions layouts/product-landing.html
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ <h2 class="link-with-intro-title f5">{{ link.title }}<span class="Bump-link-symb
<div class="col-12 col-lg-4 mb-4 mb-lg-0">
<div class="featured-links-heading mb-4 d-flex flex-items-baseline">
<h3 class="f4 text-normal text-mono text-uppercase color-gray-5">{% data ui.toc.whats_new %}</h3>
<a href="https://github.blog/changelog/" class="ml-4">View all {% octicon "arrow-right" height="14" class="v-align-middle" %}</a>
<a href="{{ changelogUrl }}" class="ml-4">View all {% octicon "arrow-right" height="14" class="v-align-middle" %}</a>
</div>
<ul class="list-style-none">
{% for link in page.changelog %}
{% for link in whatsNewChangelog %}
<li class="border-top">
<a href="{{ link.href }}" class="d-block text-gray-dark Bump-link--hover py-3 no-underline">
<a href="{{ link.href }}" class="d-block text-gray-dark Bump-link--hover py-3 no-underline capitalize">
<h4>{{ link.title }} <span class="Bump-link-symbol"></span></h4>
<time
class="tooltipped tooltipped-n text-gray-light text-mono mt-1"
Expand Down
42 changes: 42 additions & 0 deletions lib/changelog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const Parser = require('rss-parser')

async function getRssFeed (url) {
const parser = new Parser({ timeout: 5000 })
const feedUrl = `${url}/feed`
let feed

try {
feed = await parser.parseURL(feedUrl)
} catch (err) {
console.error(`cannot get ${feedUrl}: ${err.message}`)
return
}

return feed
}

async function getChangelogItems (prefix, feed) {
if (!feed || !feed.items) {
console.log(feed)
console.error('feed is not valid or has no items')
return
}

// only show the first 3 posts
const changelog = feed.items
.slice(0, 3)
.map(item => {
// remove the prefix if it exists (Ex: 'GitHub Actions: '), where the colon and expected whitespace should be hardcoded.
const title = prefix ? item.title.replace(new RegExp(`^${prefix}`), '') : item.title
return {
// capitalize the first letter of the title
title: title.trim().charAt(0).toUpperCase() + title.slice(1),
date: item.isoDate,
href: item.guid
}
})

return changelog
}

module.exports = { getRssFeed, getChangelogItems }
12 changes: 4 additions & 8 deletions lib/frontmatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,10 @@ const schema = {
},
// Shown in `product-landing.html` "What's new" section
changelog: {
type: 'array',
items: {
type: 'object',
properties: {
title: { type: 'string' },
date: { type: 'string', format: 'date' },
href: { type: 'string' }
}
type: 'object',
properties: {
label: { type: 'string' },
prefix: { type: 'string' }
}
},
type: {
Expand Down
13 changes: 13 additions & 0 deletions middleware/contextualizers/whats-new-changelog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const { getRssFeed, getChangelogItems } = require('../../lib/changelog')

module.exports = async function whatsNewChangelog (req, res, next) {
if (!req.context.page) return next()
if (!req.context.page.changelog) return next()
req.context.changelogUrl = req.context.page.changelog.label === 'education'
? 'https://github.blog/category/community/education'
: `https://github.blog/changelog/label/${req.context.page.changelog.label}`

const feed = await getRssFeed(req.context.changelogUrl)
req.context.whatsNewChangelog = await getChangelogItems(req.context.page.changelog.prefix, feed)
return next()
}
1 change: 1 addition & 0 deletions middleware/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ module.exports = function (app) {
app.use(instrument('./contextualizers/graphql'))
app.use(instrument('./contextualizers/rest'))
app.use(instrument('./contextualizers/webhooks'))
app.use(asyncMiddleware(instrument('./contextualizers/whats-new-changelog')))
app.use(asyncMiddleware(instrument('./breadcrumbs')))
app.use(asyncMiddleware(instrument('./early-access-breadcrumbs')))
app.use(asyncMiddleware(instrument('./enterprise-server-releases')))
Expand Down
23 changes: 18 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"resolve-url-loader": "^3.1.2",
"revalidator": "^0.3.1",
"rimraf": "^3.0.0",
"rss-parser": "^3.12.0",
"sass": "^1.26.3",
"sass-loader": "^9.0.2",
"search-with-your-keyboard": "1.1.0",
Expand Down
4 changes: 0 additions & 4 deletions stylesheets/type.scss
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ summary {
}
}





// all h3 headers that are links should be blue-500
// except those on each product's toc
h3 a {
Expand Down
103 changes: 103 additions & 0 deletions tests/fixtures/rss-feed.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"

xmlns:georss="http://www.georss.org/georss"
xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
>

<channel>
<title>api &#8211; The GitHub Blog</title>
<atom:link href="https://github.blog/changelog/label/api/feed/" rel="self" type="application/rss+xml" />
<link>https://github.blog</link>
<description>Updates, ideas, and inspiration from GitHub to help developers build and design software.</description>
<lastBuildDate>Thu, 01 Apr 2021 20:48:29 +0000</lastBuildDate>
<language>en-US</language>
<sy:updatePeriod>
hourly </sy:updatePeriod>
<sy:updateFrequency>
1 </sy:updateFrequency>
<generator>https://wordpress.org/?v=5.7</generator>

<image>
<url>https://github.blog/wp-content/uploads/2019/01/cropped-github-favicon-512.png?fit=32%2C32</url>
<title>api &#8211; The GitHub Blog</title>
<link>https://github.blog</link>
<width>32</width>
<height>32</height>
</image>
<site xmlns="com-wordpress:feed-additions:1">153214340</site> <item>
<title>Authentication token format updates are generally available</title>
<link>https://github.blog/changelog/2021-03-31-authentication-token-format-updates-are-generally-available</link>

<dc:creator><![CDATA[phanatic]]></dc:creator>
<pubDate>Wed, 31 Mar 2021 22:22:03 +0000</pubDate>
<guid isPermaLink="false">https://github.blog/changelog/2021-03-31-authentication-token-format-updates-are-generally-available</guid>

<description><![CDATA[Authentication token format updates are generally available]]></description>
<content:encoded><![CDATA[<p>As we <a href="https://github.blog/changelog/2021-03-04-authentication-token-format-updates">announced previously</a>, the format of GitHub authentication tokens has changed. The following token types are affected:</p>
<ul>
<li><a href="https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token">Personal Access Tokens</a></li>
<li><a href="https://docs.github.com/en/developers/apps/authorizing-oauth-apps">OAuth Access Tokens</a></li>
<li><a href="https://docs.github.com/en/developers/apps/identifying-and-authorizing-users-for-github-apps">GitHub App User-to-Server Tokens</a></li>
<li><a href="https://docs.github.com/en/developers/apps/authenticating-with-github-apps#authenticating-as-an-installation">GitHub App Server-to-Server Tokens</a></li>
<li><a href="https://docs.github.com/en/developers/apps/refreshing-user-to-server-access-tokens">Refresh Tokens</a></li>
</ul>
<p>If you use any of these tokens, we encourage you to reset them now. This will give you additional security benefits and allow <a href="https://docs.github.com/en/code-security/secret-security/about-secret-scanning">Secret Scanning</a> to detect the tokens. </p>
<p>Notably, the token formats now include the following updates:</p>
<ul>
<li>The character set changed from <code>[a-f0-9]</code> to <code>[A-Za-z0-9_]</code></li>
<li>The format now includes a prefix for each token type:
<ul>
<li><code>ghp_</code> for Personal Access Tokens</li>
<li><code>gho_</code> for OAuth Access tokens</li>
<li><code>ghu_</code> for GitHub App user-to-server tokens</li>
<li><code>ghs_</code> for GitHub App server-to-server tokens</li>
<li><code>ghr_</code> for GitHub App refresh tokens</li>
</ul>
</li>
</ul>
<p>The length of our tokens is remaining the same for now. However, GitHub tokens will likely increase in length in future updates, so integrators should plan to support tokens up to 255 characters after June 1, 2021.</p>
]]></content:encoded>



<post-id xmlns="com-wordpress:feed-additions:1">57117</post-id> </item>
<item>
<title>Compare REST API now supports pagination</title>
<link>https://github.blog/changelog/2021-03-22-compare-rest-api-now-supports-pagination</link>

<dc:creator><![CDATA[phanatic]]></dc:creator>
<pubDate>Tue, 23 Mar 2021 02:49:54 +0000</pubDate>
<guid isPermaLink="false">https://github.blog/changelog/2021-03-22-compare-rest-api-now-supports-pagination</guid>

<description><![CDATA[Compare REST API now supports pagination]]></description>
<content:encoded><![CDATA[<p>The <a href="https://docs.github.com/rest/reference/repos#compare-two-commits">&quot;Compare two commits&quot;</a> REST API, which returns a list of commits reachable from one commit (or branch) but not reachable from another, now supports pagination. It can also now return the results for comparisons over 250 commits.</p>
<p>To learn more, see the <a href="https://docs.github.com/rest/reference/repos#compare-two-commits">compare two commits</a> API reference or the guide for <a href="https://docs.github.com/en/rest/guides/traversing-with-pagination">using pagination</a>.</p>
]]></content:encoded>



<post-id xmlns="com-wordpress:feed-additions:1">56979</post-id> </item>
<item>
<title>GitHub Discussions GraphQL API public beta</title>
<link>https://github.blog/changelog/2021-02-23-github-discussions-graphql-api-public-beta</link>

<dc:creator><![CDATA[phanatic]]></dc:creator>
<pubDate>Tue, 23 Feb 2021 18:21:40 +0000</pubDate>
<guid isPermaLink="false">https://github.blog/changelog/2021-02-23-github-discussions-graphql-api-public-beta</guid>

<description><![CDATA[GitHub Discussions GraphQL API public beta]]></description>
<content:encoded><![CDATA[<p>The GitHub Discussions GraphQL API public beta is now available. Get started with the <a href="https://docs.github.com/en/graphql/guides/using-the-graphql-api-for-discussions">GitHub Discussions API</a>.</p>
<p>For questions or feedback, visit <a href="https://github.com/github/feedback/discussions/categories/discussions-feedback">GitHub Discussions feedback</a>.</p>
]]></content:encoded>



<post-id xmlns="com-wordpress:feed-additions:1">56364</post-id> </item>
</channel>
</rss>
Loading

0 comments on commit bbd9f03

Please sign in to comment.