Skip to content

Commit

Permalink
Merge pull request github#5662 from github/repo-sync
Browse files Browse the repository at this point in the history
repo sync
  • Loading branch information
Octomerger authored Apr 23, 2021
2 parents 1a0f3ee + b4f5e04 commit cfd2877
Show file tree
Hide file tree
Showing 25 changed files with 584 additions and 31 deletions.
3 changes: 2 additions & 1 deletion feature-flags.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"FEATURE_TEST_TRUE": true,
"FEATURE_TEST_FALSE": false
"FEATURE_TEST_FALSE": false,
"FEATURE_NEW_SITETREE": false
}
8 changes: 8 additions & 0 deletions includes/article.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ <h2 id="in-this-article" class="f5 mb-2"><a class="Link--primary" href="#in-this
{% include featured-links %}
{% endif %}
{{ renderedPage }}

{% if tocItems and tocItems.length %}
{% if page.documentType == "category" or page.relativePath == "github/index.md" %}
{% include generic-toc-list %}
{% else %}
{% include generic-toc-items %}
{% endif %}
{% endif %}
</div>
</div>

Expand Down
14 changes: 14 additions & 0 deletions includes/breadcrumbs.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
{% if FEATURE_NEW_SITETREE %}
<nav class="breadcrumbs f5" aria-label="Breadcrumb">
{% for breadcrumb in breadcrumbs %}
{% if breadcrumb.href == '' %}
<span title="{{ breadcrumb.documentType }}: {{ breadcrumb.title }}">{{ breadcrumb.title }}</span>
{% else %}
<a title="{{ breadcrumb.documentType }}: {{ breadcrumb.title }}" href="{{ breadcrumb.href }}" class="d-inline-block {% if breadcrumb.href == currentPath %}text-gray-light{% endif %}">
{{ breadcrumb.title }}
</a>
{% endif %}
{% endfor %}
</nav>
{% else %}
<nav class="breadcrumbs f5" aria-label="Breadcrumb">
{% for breadcrumb in breadcrumbs %}
{% if breadcrumb[1].href == '' %}
Expand All @@ -9,3 +22,4 @@
{% endif %}
{% endfor %}
</nav>
{% endif %}
34 changes: 34 additions & 0 deletions includes/category-articles-list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{% for categoryPage in currentProductTree.childPages %}
{% if categoryPage.href == currentPath %}{% assign currentCategory = categoryPage %}{% endif %}
{% endfor %}

{% if currentCategory.page.shortTitle and currentCategory.page.shortTitle != '' %}{% assign currentCategoryTitle = currentCategory.page.shortTitle %}{% else %}{% assign currentCategoryTitle = currentCategory.page.title %}{% endif %}

{% assign maxArticles = 10 %}

<div class="py-6 all-articles-list">
<h2 class="font-mktg mb-4">{{ currentCategoryTitle }} docs</h2>

<div class="d-flex gutter flex-wrap">
{% for childPage in currentCategory.childPages %}
{% unless childPage.page.hidden %}
<div class="col-12 col-lg-4 mb-6 height-full">
<h4 class="mb-3"><a href="{{ childPage.href }}">{{ childPage.page.title }}</a></h4>
<ul class="list-style-none">
{% for grandchildPage in childPage.childPages %}
<li class="mb-3 {% if forloop.index > maxArticles %}d-none{% endif %}">
<a href="{{ grandchildPage.href }}">
{{ grandchildPage.page.title }}
</a>
</li>
{% endfor %}
{% assign numArticles = childPage.childPages | obj_size %}
{% if numArticles > maxArticles %}
<button class="js-all-articles-show-more btn-link Link--secondary">Show {{ numArticles | minus: maxArticles }} more {% octicon "chevron-up" class="v-align-text-bottom" %}</button>
{% endif %}
</ul>
</div>
{% endunless %}
{% endfor %}
</div>
</div>
12 changes: 12 additions & 0 deletions includes/generic-toc-items.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% if tocItems %}

{% for tocItem in tocItems %}

{% assign title = tocItem.title %}
{% assign fullPath = tocItem.fullPath %}
{% assign intro = tocItem.intro %}
{% include liquid-tags/link-with-intro %}

{% endfor %}

{% endif %}
24 changes: 24 additions & 0 deletions includes/generic-toc-list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{% if tocItems %}
<ul>
{% for tocItem in tocItems %}

{% assign title = tocItem.title %}
{% assign fullPath = tocItem.fullPath %}
{% assign intro = tocItem.intro %}

<li>{% include liquid-tags/link %}
{% if tocItem.childTocItems %}
{% unless page.relativePath == "github/index.md" %}
<ul>
{% for childItem in tocItem.childTocItems %}
{% assign title = childItem.title %}
{% assign fullPath = childItem.fullPath %}
<li>{% include liquid-tags/link %}</li>
{% endfor %}
</ul>
{% endunless %}
{% endif %}
</li>
{% endfor %}
</ul>
{% endif %}
46 changes: 46 additions & 0 deletions includes/product-articles-list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{% assign maxArticles = 10 %}

{% if currentProductTree.page.shortTitle and currentProductTree.page.shortTitle != '' %}{% assign productTitle = currentProductTree.page.shortTitle %}{% else %}{% assign productTitle = currentProductTree.page.title %}{% endif %}

<div class="py-6 all-articles-list">
<h2 class="font-mktg mb-4">All {{ productTitle }} docs</h2>

<div class="d-flex gutter flex-wrap">
{% for childPage in currentProductTree.childPages %}
{% if childPage.page.documentType == "article" %}{% assign standaloneCategory = true %}{% else %}{% assign standaloneCategory = false %}{% endif %}
{% unless standaloneCategory %}
<div class="col-12 col-lg-4 mb-6 height-full">
<h4 class="mb-3"><a href="{{ childPage.href }}">{{ childPage.page.title }}</a></h4>

{% if childPage.childPages and childPage.childPages[0].page.documentType == "mapTopic" %}
<ul class="list-style-none">
{% for grandchildPage in childPage.childPages %}
{% unless grandchildPage.page.hidden %}
{% assign numArticles = childPage.childPages | obj_size %}
<li class="mb-3 {% if forloop.index > maxArticles %}d-none{% endif %}">
<a href="{{ grandchildPage.href }}">
{{ grandchildPage.page.title }}
</a>
</li>
{% if numArticles > maxArticles %}
<button class="js-all-articles-show-more btn-link Link--secondary">Show {{ numArticles | minus: maxArticles }} more {% octicon "chevron-up" class="v-align-text-bottom" %}</button>
{% endif %}
{% endunless %}
{% endfor %}
</ul>
{% else %}
<ul class="list-style-none">
{% assign numArticles = childPage.childPages | obj_size %}
{% for grandchildPage in childPage.childPages %}
<li class="mb-3 {% if forloop.index > maxArticles %}d-none{% endif %}"><a href="{{ grandchildPage.href }}">{{ grandchildPage.page.title }}</a></li>
{% endfor %}
</ul>
{% if numArticles > maxArticles %}
<button class="js-all-articles-show-more btn-link Link--secondary">Show {{ numArticles | minus: maxArticles }} more {% octicon "chevron-up" class="v-align-text-bottom" %}</button>
{% endif %}
{% endif %}
</div>
{% endunless %}
{% endfor %}
</div>
</div>
74 changes: 74 additions & 0 deletions includes/sidebar-product.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<!--
Styling note:
Categories, Maptopics, and Articles list items get a class of `active` when they correspond to content
hierarchy of the current page. If an item's URL is also the same as the current URL, the item
also gets an `is-current-page` class.
-->

{% include all-products-link %}

{% unless currentProductTree.page.hidden %}

{% if currentProductTree.renderedShortTitle %}{% assign productTitle = currentProductTree.renderedShortTitle %}{% else %}{% assign productTitle = currentProductTree.renderedFullTitle %}{% endif %}

<li title="" class="sidebar-product mb-2">
<a href="{{currentProductTree.href}}" class="pl-4 pr-5 pb-1 f4">{{ productTitle }}</a>
</li>
<li>
<ul class="sidebar-categories list-style-none">
{% for childPage in currentProductTree.childPages %}
{% if childPage.page.documentType == "article" %}{% assign standaloneCategory = true %}{% else %}{% assign standaloneCategory = false %}{% endif %}
<li class="sidebar-category py-1 {% if currentPath contains childPage.href %}active {% if currentPath == childPage.href %}is-current-page {% endif %}{% endif %}{% if standaloneCategory %}standalone-category{% endif %}">
{% if childPage.renderedShortTitle %}{% assign childTitle = childPage.renderedShortTitle %}{% else %}{% assign childTitle = childPage.renderedFullTitle %}{% endif %}
{% if standaloneCategory %}
<a href="{{childPage.href}}" class="pl-4 pr-2 py-2 f6 text-uppercase d-block flex-auto mr-3">{{ childTitle }}</a>
{% else %}
<details class="dropdown-withArrow details details-reset" {% if currentPath contains childPage.href or forloop.index < 4 %}open{% endif %}>
<summary>
<div class="d-flex flex-justify-between">
<a href="{{childPage.href}}" class="pl-4 pr-2 py-2 f6 text-uppercase d-block flex-auto mr-3">{{ childTitle }}</a>
{% if forloop.index < 4 %}
<svg xmlns="http://www.w3.org/2000/svg" class="octicon flex-shrink-0 arrow mr-3" style="margin-top:7px" viewBox="0 0 16 16" width="16" height="16"> <path fill-rule="evenodd" clip-rule="evenodd" d="M12.7803 6.21967C13.0732 6.51256 13.0732 6.98744 12.7803 7.28033L8.53033 11.5303C8.23744 11.8232 7.76256 11.8232 7.46967 11.5303L3.21967 7.28033C2.92678 6.98744 2.92678 6.51256 3.21967 6.21967C3.51256 5.92678 3.98744 5.92678 4.28033 6.21967L8 9.93934L11.7197 6.21967C12.0126 5.92678 12.4874 5.92678 12.7803 6.21967Z"></path></svg>
{% endif %}
</div>
</summary>
{% endif %}
<!-- some categories have maptopics with child articles -->
{% if currentPath contains childPage.href or forloop.index < 4 %}
{% if childPage.childPages[0].page.documentType == "mapTopic" %}
<ul class="sidebar-topics list-style-none position-relative">
{% for grandchildPage in childPage.childPages %}
{% if grandchildPage.renderedShortTitle %}{% assign grandchildTitle = grandchildPage.renderedShortTitle %}{% else %}{% assign grandchildTitle = grandchildPage.renderedFullTitle %}{% endif %}
<li class="sidebar-maptopic {% if currentPath contains grandchildPage.href %}active {% if currentPath == grandchildPage.href %}is-current-page{% endif %}{% endif %}">
<a href="{{grandchildPage.href}}" class="pl-4 pr-5 py-2">{{ grandchildTitle }} </a>
<ul class="sidebar-articles my-2">
{% for greatgrandchildPage in grandchildPage.childPages %}
{% if greatgrandchildPage.renderedShortTitle %}{% assign greatgrandchildTitle = greatgrandchildPage.renderedShortTitle %}{% else %}{% assign greatgrandchildTitle = greatgrandchildPage.renderedFullTitle %}{% endif %}
<li class="sidebar-article {% if currentPath contains greatgrandchildPage.href %}active {% if currentPath == greatgrandchildPage.href %}is-current-page{% endif %}{% endif %}">
<a href="{{greatgrandchildPage.href}}" class="pl-6 pr-5 py-1{% if forloop.last %} pb-2{% endif %}">{{ greatgrandchildTitle }}</a>
</li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
<!-- some categories have no maptopics, only articles -->
{% elsif childPage.childPages[0].page.documentType == "article" %}
<ul class="sidebar-articles list-style-none">
{% for grandchildPage in childPage.childPages %}
{% if grandchildPage.renderedShortTitle %}{% assign grandchildTitle = grandchildPage.renderedShortTitle %}{% else %}{% assign grandchildTitle = grandchildPage.renderedFullTitle %}{% endif %}
<li class="sidebar-article {% if currentPath contains grandchildPage.href %}active {% if currentPath == grandchildPage.href %}is-current-page{% endif %}{% endif %}">
<a href="{{grandchildPage.href}}" class="pl-4 pr-5 py-1{% if forloop.last %} pb-2{% endif %}">{{ grandchildTitle }}</a>
</li>
{% endfor %}
</ul>
{% endif %}
{% endif %}
</details>
</li>
{% endfor %}
</ul>
</li>

{% endunless %}
4 changes: 4 additions & 0 deletions includes/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
</ul>
{% else %}
<ul class="sidebar-products">
{% if FEATURE_NEW_SITETREE %}
{% include sidebar-product %}
{% else %}
{% include sidebar-specific-product %}
{% endif %}
</ul>
{% endif %}
</nav>
Expand Down
11 changes: 11 additions & 0 deletions layouts/product-landing.html
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,22 @@ <h2 class="font-mktg h1 mb-2">Guides</h2>
{% endif %}

<div class="container-xl px-3 px-md-6 mt-6">
{% if FEATURE_NEW_SITETREE %}
{% if page.documentType == "category" %}
{% include category-articles-list %}
{% endif %}
{% if page.documentType == "product" %}
{% include product-articles-list %}
{% endif %}
{% endif %}

{% unless FEATURE_NEW_SITETREE %}
{% if currentCategory %}
{% include all-articles-category %}
{% else %}
{% include all-articles-product %}
{% endif %}
{% endunless %}
</div>

{% include support-section %}
Expand Down
17 changes: 5 additions & 12 deletions lib/create-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module.exports = async function createTree (originalPath, langObj) {
const localizedBasePath = path.posix.join(__dirname, '..', langObj.dir, 'content')

// Initialize the Page! This is where the file reads happen.
let page = await Page.init({
const page = await Page.init({
basePath: localizedBasePath,
relativePath,
languageCode: langObj.code
Expand All @@ -29,17 +29,10 @@ module.exports = async function createTree (originalPath, langObj) {
if (!page) {
// Do not throw an error if Early Access is not available.
if (relativePath.startsWith('early-access')) return
// If a translated path doesn't exist, fall back to the English so there is parity between
// the English tree and the translated trees.
if (langObj.code !== 'en') {
page = await Page.init({
basePath: basePath,
relativePath,
languageCode: langObj.code
})
}

if (!page) throw Error(`Cannot initialize page for ${filepath}`)
// Do not throw an error if translated page is not available.
if (langObj.code !== 'en') return

throw Error(`Cannot initialize page for ${filepath} in ${langObj.code}`)
}

// Create the root tree object on the first run, and create children recursively.
Expand Down
2 changes: 1 addition & 1 deletion lib/redirects/add-redirect-to-frontmatter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// add a new redirect string to redirect_from frontmatter

module.exports = function addRedirectToFrontmatter (redirectFromData, newRedirectString) {
if (Array.isArray(redirectFromData)) {
if (Array.isArray(redirectFromData) && !redirectFromData.includes(newRedirectString)) {
redirectFromData.push(newRedirectString)
} else if (typeof redirectFromData === 'string') {
redirectFromData = [redirectFromData]
Expand Down
55 changes: 55 additions & 0 deletions middleware/categories-for-support.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const path = require('path')
const renderOpts = { textOnly: true, encodeEntities: true }

// This middleware exposes a list of all categories and child articles at /categories.json.
// GitHub Support uses this for internal ZenDesk search functionality.
module.exports = async function categoriesForSupport (req, res, next) {
const englishSiteTree = req.context.siteTree.en

const allCategories = []

await Promise.all(Object.keys(englishSiteTree).map(async (version) => {
await Promise.all(englishSiteTree[version].childPages.map(async (productPage) => {
if (productPage.page.relativePath.startsWith('early-access')) return
if (!productPage.childPages) return

await Promise.all(productPage.childPages.map(async (categoryPage) => {
// We can't get the rendered titles from middleware/render-tree-titles
// here because that middleware only runs on the current version, and this
// middleware processes all versions.
const name = categoryPage.page.title.includes('{')
? await categoryPage.page.renderProp('title', req.context, renderOpts)
: categoryPage.page.title

allCategories.push({
name,
published_articles: await findArticlesPerCategory(categoryPage, [], req.context)
})
}))
}))
}))

return res.json(allCategories)
}

async function findArticlesPerCategory (currentPage, articlesArray, context) {
if (currentPage.page.documentType === 'article') {
const title = currentPage.page.title.includes('{')
? await currentPage.page.renderProp('title', context, renderOpts)
: currentPage.page.title

articlesArray.push({
title,
slug: path.basename(currentPage.href)
})
}

if (!currentPage.childPages) return articlesArray

// Run recursively to find any articles deeper in the tree.
await Promise.all(currentPage.childPages.map(async (childPage) => {
await findArticlesPerCategory(childPage, articlesArray, context)
}))

return articlesArray
}
4 changes: 2 additions & 2 deletions middleware/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const {
getPathWithoutLanguage
} = require('../lib/path-utils')
const productNames = require('../lib/product-names')
const warmServer = require('../lib/warm-server')
const warmServer = process.env.FEATURE_NEW_SITETREE ? require('../lib/warm-server2') : require('../lib/warm-server')
const featureFlags = Object.keys(require('../feature-flags'))
const builtAssets = require('../lib/built-asset-urls')
const searchVersions = require('../lib/search/versions')
Expand All @@ -27,7 +27,7 @@ module.exports = async function contextualize (req, res, next) {
// make feature flag environment variables accessible in layouts
req.context.process = { env: {} }
featureFlags.forEach(featureFlagName => {
req.context.process.env[featureFlagName] = process.env[featureFlagName]
req.context[featureFlagName] = process.env[featureFlagName]
})

// define each context property explicitly for code-search friendliness
Expand Down
Loading

0 comments on commit cfd2877

Please sign in to comment.