Skip to content

Commit 311171a

Browse files
authored
Merge pull request #16965 from github/revert-16952-revert-16947-optimize-sitetree
Site tree optimizations
2 parents cedab43 + 72d21ee commit 311171a

File tree

17 files changed

+117
-94
lines changed

17 files changed

+117
-94
lines changed

content/developers/github-marketplace/creating-apps-for-github-marketplace.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@ intro: 'You can list free and paid tools for developers to use in {% data variab
44
mapTopic: true
55
versions:
66
free-pro-team: '*'
7-
enterprise-server: '*'
87
---
98

content/github/site-policy/github-insights-and-data-protection-for-your-organization.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ intro: '{% data variables.product.prodname_insights %} analyzes your {% data var
44
product: '{% data reusables.gated-features.github-insights %}'
55
redirect_from:
66
- /github/installing-and-configuring-github-insights/github-insights-and-data-protection-for-your-organization
7+
- /enterprise-server@2.22/github/site-policy/github-insights-and-data-protection-for-your-organization
8+
- /enterprise-server@2.21/github/site-policy/github-insights-and-data-protection-for-your-organization
9+
- /enterprise-server@2.20/github/site-policy/github-insights-and-data-protection-for-your-organization
710
versions:
8-
enterprise-server: '*'
11+
free-pro-team: '*'
912
---
1013

1114
For more information about the terms that govern {% data variables.product.prodname_insights %}, see your {% data variables.product.prodname_ghe_one %} subscription agreement.

content/insights/installing-and-configuring-github-insights/about-data-in-github-insights.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ You can choose which contributors are included in metrics and create teams of co
1919

2020
### Further reading
2121
- "[Metrics available with {% data variables.product.prodname_insights %}](/insights/exploring-your-usage-of-github-enterprise/metrics-available-with-github-insights)"
22-
- "[{% data variables.product.prodname_insights %} and data protection for your organization](/github/site-policy/github-insights-and-data-protection-for-your-organization)"
22+
- "<a href="/github/site-policy/github-insights-and-data-protection-for-your-organization" class="dotcom-only">{% data variables.product.prodname_insights %} and data protection for your organization</a>"

content/insights/installing-and-configuring-github-insights/installing-github-insights.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,4 @@ To configure {% data variables.product.prodname_insights %} to connect to {% dat
108108
### Further reading
109109

110110
- "[Managing repositories](/insights/installing-and-configuring-github-insights/managing-repositories)"
111-
- "[{% data variables.product.prodname_insights %} and data protection for your organization](/github/site-policy/github-insights-and-data-protection-for-your-organization)"
111+
- "<a href="/github/site-policy/github-insights-and-data-protection-for-your-organization" class="dotcom-only">{% data variables.product.prodname_insights %} and data protection for your organization</a>"

includes/breadcrumbs.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{% if breadcrumb[1].href == '' %}
44
<span>{{breadcrumb[1].title}}</span>
55
{% else %}
6-
<a title="{{ breadcrumb[0]}}: {{breadcrumb[1].title}}" href="/{{currentLanguage}}{{breadcrumb[1].href}}" class="d-inline-block {% if breadcrumb[1].href == currentPathWithoutLanguage %}text-gray-light{% endif %}">
6+
<a title="{{ breadcrumb[0]}}: {{breadcrumb[1].title}}" href="{{{breadcrumb[1].href}}" class="d-inline-block {% if breadcrumb[1].href == currentPath %}text-gray-light{% endif %}">
77
{{breadcrumb[1].title}}</a>
88
{% endif %}
99
{% endfor %}

includes/sidebar-guides.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<ul class="sidebar-categories">
22
{% for category in product[1].categories %}
33
<li class="sidebar-category {% if breadcrumbs.category.href == category[1].href %}active{% endif %}">
4-
<a href="/{{currentLanguage}}{{category[1].href}}">{{ category[1].title }}</a>
4+
<a href="{{category[1].href}}">{{ category[1].title }}</a>
55
<!-- some categories have topics with child articles -->
66
{% if category[1].maptopics %}
77
<ul class="sidebar-maptopics">
88
{% for maptopic in category[1].maptopics %}
99
<li class="sidebar-maptopic {% if breadcrumbs.maptopic.href == maptopic[1].href %}active{% endif %}">
10-
<a href="/{{currentLanguage}}{{maptopic[1].href}}">{{ maptopic[1].title }}</a>
10+
<a href="{{maptopic[1].href}}">{{ maptopic[1].title }}</a>
1111
<ul class="sidebar-articles">
1212
{% for article in maptopic[1].articles %}
1313
<li class="sidebar-article {% if currentPath == article[1].href %}active{% endif %}">
14-
<a href="/{{currentLanguage}}{{article[1].href}}">{{ article[1].title }}</a>
14+
<a href="{{article[1].href}}">{{ article[1].title }}</a>
1515
</li>
1616
{% endfor %}
1717
</ul>
@@ -23,7 +23,7 @@
2323
<ul class="sidebar-articles">
2424
{% for article in category[1].articles %}
2525
<li class="sidebar-article{% if currentPath == article[1].href %} active{% endif %}">
26-
<a href="/{{currentLanguage}}{{article[1].href}}">{{ article[1].title }}</a>
26+
<a href="{{article[1].href}}">{{ article[1].title }}</a>
2727
</li>
2828
{% endfor %}
2929
</ul>

includes/sidebar-specific-product.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
{% include all-products-link %}
1111
<li title="{{product.title}}" class="sidebar-product mb-2">
1212
{% unless page.hidden %}
13-
<a href="/{{currentLanguage}}{{product.href}}" class="pl-4 pr-5 pb-1 f4">{{ product.title }}</a>
13+
<a href="{{product.href}}" class="pl-4 pr-5 pb-1 f4">{{ product.title }}</a>
1414
{% endunless %}
1515
</li>
1616
<ul class="sidebar-categories list-style-none">
1717
{% for category in product.categories %}
18-
{% capture fullPathToCategory %}/{{currentLanguage}}{{category[1].href}}{% endcapture %}
18+
{% capture fullPathToCategory %}{{category[1].href}}{% endcapture %}
1919

2020
<li class="sidebar-category py-1 {% if breadcrumbs.category.href == category[1].href %}active {% if currentPath == fullPathToCategory %}is-current-page {% endif %}{% endif %}{% if category[1].standalone %}standalone-category{% endif %}">
2121
{% if category[1].standalone %}
@@ -37,13 +37,13 @@
3737
<ul class="sidebar-topics list-style-none position-relative">
3838
{% for maptopic in category[1].maptopics %}
3939
{% unless maptopic[1].hidden %}
40-
{% capture fullPathToMaptopic %}/{{currentLanguage}}{{maptopic[1].href}}{% endcapture %}
40+
{% capture fullPathToMaptopic %}{{maptopic[1].href}}{% endcapture %}
4141

4242
<li class="sidebar-maptopic {% if breadcrumbs.maptopic.href == maptopic[1].href %}active {% if currentPath == fullPathToMaptopic %}is-current-page{% endif %}{% endif %}">
4343
<a href="{{fullPathToMaptopic}}" class="pl-4 pr-5 py-2">{{ maptopic[1].title }}</a>
4444
<ul class="sidebar-articles my-2">
4545
{% for article in maptopic[1].articles %}
46-
{% capture fullPathToArticle %}/{{currentLanguage}}{{article[1].href}}{% endcapture %}
46+
{% capture fullPathToArticle %}{{article[1].href}}{% endcapture %}
4747

4848
<li class="sidebar-article {% if breadcrumbs.article.href == article[1].href %}active {% if currentPath == fullPathToArticle %}is-current-page{% endif %}{% endif %}">
4949
<a href="{{fullPathToArticle}}" class="pl-6 pr-5 py-1{% if forloop.last %} pb-2{% endif %}">{{ article[1].title }}</a>
@@ -58,7 +58,7 @@
5858
{% else %}
5959
<ul class="sidebar-articles list-style-none">
6060
{% for article in category[1].articles %}
61-
{% capture fullPathToArticle %}/{{currentLanguage}}{{article[1].href}}{% endcapture %}
61+
{% capture fullPathToArticle %}{{article[1].href}}{% endcapture %}
6262
<li class="sidebar-article {% if breadcrumbs.article.href == article[1].href %}active {% if currentPath == fullPathToArticle %}is-current-page{% endif %}{% endif %}">
6363
<a href="{{fullPathToArticle}}" class="pl-4 pr-5 py-1{% if forloop.last %} pb-2{% endif %}">{{ article[1].title }}</a>
6464
</li>

lib/get-map-topic-content.js

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
1-
const findPage = require('./find-page')
1+
const { get, last } = require('lodash')
2+
const { getLanguageCode } = require('../lib/patterns')
23

3-
// get the page.childArticles set on english map topics in lib/site-tree.js
4-
module.exports = function getMapTopicContent (page, pageMap, redirects) {
5-
const englishPage = page.languageCode !== 'en'
6-
? findPage(`/${page.relativePath.replace(/.md$/, '')}`, pageMap, redirects, 'en')
7-
: page
4+
// get the childArticles set on map topics in lib/site-tree.js
5+
module.exports = function getMapTopicContent (productId, siteTree, currentLanguage, currentVersion, currentPath) {
6+
const maptopicPath = currentPath
7+
const categoryPath = currentPath.replace(new RegExp(`/${last(currentPath.split('/'))}$`), '')
8+
const siteTreePath = getSiteTreePath(currentVersion, productId, categoryPath, maptopicPath)
9+
let childArticles = get(siteTree[currentLanguage], siteTreePath)
810

9-
if (!englishPage) {
10-
console.error(`cannot find english page: ${page.fullPath}`)
11-
return
11+
// try falling back to English if needed
12+
if (!childArticles && currentLanguage !== 'en') {
13+
const englishCategoryPath = categoryPath.replace(getLanguageCode, '/en')
14+
const englishMaptopicPath = maptopicPath.replace(getLanguageCode, '/en')
15+
const englishSiteTreePath = getSiteTreePath(currentVersion, productId, englishCategoryPath, englishMaptopicPath)
16+
childArticles = get(siteTree.en, englishSiteTreePath)
1217
}
1318

14-
if (!englishPage.childArticles) {
15-
console.error(`error getting child articles on map topic: ${page.fullPath}`)
16-
return
19+
if (!childArticles) {
20+
console.error(`can't find child articles for map topic ${currentPath}`)
21+
return ''
1722
}
1823

19-
return englishPage.childArticles
24+
return childArticles
2025
.map(article => `{% link_with_intro /${article.href} %}`)
2126
.join('\n\n')
2227
}
28+
29+
function getSiteTreePath (version, productId, categoryPath, maptopicPath) {
30+
return [version, 'products', productId, 'categories', categoryPath, 'maptopics', maptopicPath, 'childArticles']
31+
}

lib/page.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,8 @@ class Page {
157157
this.shortTitle = await renderContent(this.shortTitle, context, { textOnly: true, encodeEntities: true })
158158

159159
let markdown = this.mapTopic
160-
? getMapTopicContent(this, context.pages, context.redirects)
160+
// get the map topic child articles from the siteTree
161+
? getMapTopicContent(this.parentProduct.id, context.siteTree, context.currentLanguage, context.currentVersion, context.currentPath)
161162
: this.markdown
162163

163164
// If the article is interactive parse the React!

lib/redirects/permalinks.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const patterns = require('../patterns')
22
const { getVersionedPathWithLanguage } = require('../path-utils')
3+
const supportedVersions = new Set(Object.keys(require('../all-versions')))
34
const getOldPathsFromPermalink = require('./get-old-paths-from-permalink')
45

56
module.exports = function generateRedirectsForPermalinks (permalinks, redirectFrontmatter) {
@@ -25,6 +26,12 @@ module.exports = function generateRedirectsForPermalinks (permalinks, redirectFr
2526
// remove trailing slashes (sometimes present in frontmatter)
2627
frontmatterOldPath = frontmatterOldPath.replace(patterns.trailingSlash, '$1')
2728

29+
// support hardcoded versions in redirect frontmatter
30+
if (supportedVersions.has(frontmatterOldPath.split('/')[1])) {
31+
redirects[frontmatterOldPath] = permalink.href
32+
redirects[`/en${frontmatterOldPath}`] = permalink.href
33+
}
34+
2835
// get the old path for the current permalink version
2936
const versionedFrontmatterOldPath = getVersionedPathWithLanguage(frontmatterOldPath, permalink.pageVersion, permalink.languageCode)
3037

lib/site-tree.js

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const path = require('path')
22
const findPageInVersion = require('./find-page-in-version')
33
const products = Object.values(require('../lib/all-products'))
4-
const { getVersionedPathWithoutLanguage } = require('./path-utils')
4+
const { getVersionedPathWithLanguage, getPathWithLanguage } = require('./path-utils')
55
const languageCodes = Object.keys(require('./languages'))
66
const addTitlesToTree = require('./site-tree-titles')
77
const allVersions = Object.keys(require('./all-versions'))
@@ -35,15 +35,16 @@ module.exports = async function buildSiteTree (pageMap, site, redirects) {
3535
return
3636
}
3737

38-
product.href = item.href
38+
// we don't want versioned product links because these links already have a default version in them
39+
product.href = getPathWithLanguage(item.href, languageCode)
3940

4041
// find the product TOC page and get TOC items
4142
const page = findPageInVersion(item.href, pageMap, redirects, languageCode, version)
4243

4344
// skip if page can't be found in this version
4445
if (!page) return
4546

46-
product.categories = buildCategoriesTree(page.tocItems, item.href, pageMap, redirects, version, languageCode)
47+
product.categories = buildCategoriesTree(page.tocItems, product.href, pageMap, redirects, version, languageCode)
4748

4849
productTree[item.id] = product
4950
return null
@@ -67,11 +68,12 @@ function buildCategoriesTree (tocItems, productHref, pageMap, redirects, version
6768

6869
const categoryHref = path.join(productHref, item.href)
6970

70-
const versionedCategoryHref = getVersionedPathWithoutLanguage(categoryHref, version)
71+
// we DO want versioned category links
72+
const versionedCategoryHref = getVersionedPathWithLanguage(categoryHref, version, languageCode)
7173
category.href = versionedCategoryHref
7274

7375
// find the category TOC page and get its TOC items
74-
const page = findPageInVersion(categoryHref, pageMap, redirects, languageCode, version)
76+
const page = findPageInVersion(versionedCategoryHref, pageMap, redirects, languageCode, version)
7577

7678
// skip if page can't be found in this version
7779
if (!page) return
@@ -90,9 +92,9 @@ function buildCategoriesTree (tocItems, productHref, pageMap, redirects, version
9092
// if TOC contains maptopics, build a maptopics tree
9193
// otherwise build an articles tree
9294
if (hasMaptopics) {
93-
category.maptopics = buildMaptopicsTree(page.tocItems, categoryHref, pageMap, redirects, version, languageCode)
95+
category.maptopics = buildMaptopicsTree(page.tocItems, versionedCategoryHref, pageMap, redirects, version, languageCode)
9496
} else {
95-
category.articles = buildArticlesTree(page.tocItems, categoryHref, pageMap, redirects, version, languageCode)
97+
category.articles = buildArticlesTree(page.tocItems, versionedCategoryHref, pageMap, redirects, version, languageCode)
9698
}
9799
}
98100

@@ -102,7 +104,7 @@ function buildCategoriesTree (tocItems, productHref, pageMap, redirects, version
102104
return categoryTree
103105
}
104106

105-
function buildMaptopicsTree (tocItems, categoryHref, pageMap, redirects, version, languageCode) {
107+
function buildMaptopicsTree (tocItems, versionedCategoryHref, pageMap, redirects, version, languageCode) {
106108
const maptopicTree = {}
107109

108110
// for every maptopic in a category TOC...
@@ -111,38 +113,32 @@ function buildMaptopicsTree (tocItems, categoryHref, pageMap, redirects, version
111113
.forEach(item => {
112114
const maptopic = {}
113115

114-
const maptopicHref = path.join(categoryHref, item.href)
115-
116-
const versionedMaptopicHref = getVersionedPathWithoutLanguage(maptopicHref, version)
116+
const versionedMaptopicHref = path.join(versionedCategoryHref, item.href)
117117
maptopic.href = versionedMaptopicHref
118118

119-
// we already have access to the child articles via the category TOC items
120-
// but we still need the page to get the available versions
121-
const page = findPageInVersion(maptopicHref, pageMap, redirects, languageCode, version)
119+
// find the category TOC page and get its TOC items
120+
const page = findPageInVersion(versionedMaptopicHref, pageMap, redirects, languageCode, version)
122121

123122
// skip if page can't be found in this version
124123
if (!page) return
125124

126125
// if this is not a maptopic, return early
127126
if (!page.mapTopic) return
128127

129-
const childArticles = getChildArticles(tocItems, item.href)
130-
131128
maptopic.title = page.title
132129
maptopic.shortTitle = page.shortTitle
133130
maptopic.hidden = page.hidden
134-
135131
// make the child articles accessible to the page object for maptopic rendering
136-
if (!page.childArticles) page.childArticles = childArticles
132+
maptopic.childArticles = getChildArticles(tocItems, item.href)
133+
maptopic.articles = buildArticlesTree(maptopic.childArticles, versionedCategoryHref, pageMap, redirects, version, languageCode)
137134

138-
maptopic.articles = buildArticlesTree(childArticles, categoryHref, pageMap, redirects, version, languageCode)
139135
maptopicTree[versionedMaptopicHref] = maptopic
140136
})
141137

142138
return maptopicTree
143139
}
144140

145-
function buildArticlesTree (tocItems, categoryHref, pageMap, redirects, version, languageCode) {
141+
function buildArticlesTree (tocItems, versionedCategoryHref, pageMap, redirects, version, languageCode) {
146142
const articleTree = {}
147143

148144
// REST categories may not have TOC items
@@ -152,12 +148,11 @@ function buildArticlesTree (tocItems, categoryHref, pageMap, redirects, version,
152148
tocItems.forEach(item => {
153149
const article = {}
154150

155-
const articleHref = path.join(categoryHref, item.href)
156-
157-
const versionedArticleHref = getVersionedPathWithoutLanguage(articleHref, version)
151+
const versionedArticleHref = path.join(versionedCategoryHref, item.href)
158152
article.href = versionedArticleHref
159153

160-
const page = findPageInVersion(articleHref, pageMap, redirects, languageCode, version)
154+
// find the category TOC page and get its TOC items
155+
const page = findPageInVersion(versionedArticleHref, pageMap, redirects, languageCode, version)
161156

162157
// skip if page can't be found in this version
163158
if (!page) return

middleware/breadcrumbs.js

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module.exports = async (req, res, next) => {
2727
}
2828

2929
req.context.breadcrumbs.product = {
30-
href: path.posix.join('/', req.context.currentVersion, productPath),
30+
href: path.posix.join('/', req.context.currentLanguage, req.context.currentVersion, productPath),
3131
title: product.title
3232
}
3333

@@ -36,7 +36,7 @@ module.exports = async (req, res, next) => {
3636
// get category path
3737
// e.g., `getting-started-with-github` in /free-pro-team@latest/github/getting-started-with-github
3838
// or /enterprise-server@2.21/github/getting-started-with-github
39-
const categoryPath = path.posix.join('/', req.context.currentVersion, productPath, pathParts[1])
39+
const categoryPath = path.posix.join('/', req.context.currentLanguage, req.context.currentVersion, productPath, pathParts[1])
4040

4141
const category = product.categories[categoryPath]
4242

@@ -53,7 +53,7 @@ module.exports = async (req, res, next) => {
5353
// e.g., /github/getting-started-with-github/learning-about-github
5454
let maptopic
5555
if (req.context.page.mapTopic) {
56-
const maptopicPath = path.posix.join(categoryPath, pathParts[2])
56+
const maptopicPath = req.path
5757

5858
maptopic = category.maptopics[maptopicPath]
5959

@@ -64,9 +64,7 @@ module.exports = async (req, res, next) => {
6464
title: maptopic.shortTitle || maptopic.title
6565
}
6666
} else {
67-
// get article path
68-
// e.g., /github/getting-started-with-github/githubs-products
69-
const articlePath = path.posix.join(categoryPath, pathParts[2])
67+
const articlePath = req.path
7068

7169
// find parent maptopic if one exists
7270
// some categories don't have maptopics, e.g. site-policy
@@ -81,17 +79,7 @@ module.exports = async (req, res, next) => {
8179
}
8280
}
8381

84-
let articleKey = '/' + req.language + articlePath
85-
let articlePage = req.context.pages[articleKey]
86-
87-
// fall back to English if localized article does not exist
88-
if (!articlePage && req.language !== 'en') {
89-
articleKey = '/en' + articlePath
90-
articlePage = req.context.pages[articleKey]
91-
}
92-
93-
if (!articlePage) return next()
94-
82+
const articlePage = req.context.page
9583
const articleTitle = await articlePage.renderProp('shortTitle', req.context, { textOnly: true, encodeEntities: true })
9684

9785
req.context.breadcrumbs.article = {

0 commit comments

Comments
 (0)