Skip to content

Commit f5b050d

Browse files
committed
updates now that siteTree paths include language codes
1 parent 748a715 commit f5b050d

6 files changed

Lines changed: 32 additions & 42 deletions

File tree

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>

middleware/breadcrumbs.js

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module.exports = async (req, res, next) => {
2323
const product = req.context.siteTree[req.language][req.context.currentVersion].products[req.context.currentProduct]
2424

2525
req.context.breadcrumbs.product = {
26-
href: path.posix.join('/', req.context.currentVersion, productPath),
26+
href: path.posix.join('/', req.context.currentLanguage, req.context.currentVersion, productPath),
2727
title: product.title
2828
}
2929

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

3737
const category = product.categories[categoryPath]
3838

@@ -77,17 +77,7 @@ module.exports = async (req, res, next) => {
7777
}
7878
}
7979

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

9383
req.context.breadcrumbs.article = {

tests/content/site-tree.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,23 @@ describe('siteTree', () => {
2424
test('object order', () => {
2525
expect(Object.keys(siteTree)[0]).toBe('en')
2626
expect(Object.keys(siteTree.en)[0]).toBe(nonEnterpriseDefaultVersion)
27-
expect(Object.keys(siteTree.en[nonEnterpriseDefaultVersion].products.github.categories)[0]).toBe(`/${nonEnterpriseDefaultVersion}/github/getting-started-with-github`)
27+
expect(Object.keys(siteTree.en[nonEnterpriseDefaultVersion].products.github.categories)[0]).toBe(`/en/${nonEnterpriseDefaultVersion}/github/getting-started-with-github`)
2828
})
2929

3030
test('object structure', () => {
3131
expect(nonEnterpriseDefaultVersion in siteTree.en).toBe(true)
3232
expect(`enterprise-server@${latestEnterpriseRelease}` in siteTree.en).toBe(true)
33-
expect(flatTree[`en.${nonEnterpriseDefaultVersion}.products.github.href`]).toBe(`/${nonEnterpriseDefaultVersion}/github`)
34-
expect(flatTree[`en.${nonEnterpriseDefaultVersion}.products.github.categories./${nonEnterpriseDefaultVersion}/github/getting-started-with-github.href`]).toBe(`/${nonEnterpriseDefaultVersion}/github/getting-started-with-github`)
33+
expect(flatTree[`en.${nonEnterpriseDefaultVersion}.products.github.href`]).toBe(`/en/${nonEnterpriseDefaultVersion}/github`)
34+
expect(flatTree[`en.${nonEnterpriseDefaultVersion}.products.github.categories./en/${nonEnterpriseDefaultVersion}/github/getting-started-with-github.href`]).toBe(`/en/${nonEnterpriseDefaultVersion}/github/getting-started-with-github`)
3535
})
3636

3737
describe('localized titles', () => {
3838
test('titles for categories', () => {
39-
const japaneseTitle = flatTree[`ja.${nonEnterpriseDefaultVersion}.products.github.categories./${nonEnterpriseDefaultVersion}/github/getting-started-with-github.title`]
39+
const japaneseTitle = flatTree[`ja.${nonEnterpriseDefaultVersion}.products.github.categories./ja/${nonEnterpriseDefaultVersion}/github/getting-started-with-github.title`]
4040
expect(typeof japaneseTitle).toBe('string')
4141
expect(japaneseCharacters.presentIn(japaneseTitle)).toBe(true)
4242

43-
const englishTitle = flatTree[`en.${nonEnterpriseDefaultVersion}.products.github.categories./${nonEnterpriseDefaultVersion}/github/getting-started-with-github.title`]
43+
const englishTitle = flatTree[`en.${nonEnterpriseDefaultVersion}.products.github.categories./en/${nonEnterpriseDefaultVersion}/github/getting-started-with-github.title`]
4444
expect(typeof englishTitle).toBe('string')
4545
expect(japaneseCharacters.presentIn(englishTitle)).toBe(false)
4646
})
@@ -52,7 +52,7 @@ describe('siteTree', () => {
5252
test('articles that include site data in liquid templating', () => {
5353
const pageWithDynamicTitle = siteTree.en[`enterprise-server@${latestEnterpriseRelease}`]
5454
.products.admin
55-
.categories[`/enterprise-server@${latestEnterpriseRelease}/admin/enterprise-support`]
55+
.categories[`/en/enterprise-server@${latestEnterpriseRelease}/admin/enterprise-support`]
5656
// Source frontmatter from article:
5757
// title: 'Working with {{ site.data.variables.contact.github_support }}'
5858
expect(pageWithDynamicTitle.title).toEqual('Working with GitHub Support')

tests/rendering/breadcrumbs.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ describe('breadcrumbs', () => {
8888
const breadcrumbs = await getJSON('/en/github?json=breadcrumbs')
8989
const expected = {
9090
product: {
91-
href: `/${nonEnterpriseDefaultVersion}/github`,
91+
href: `/en/${nonEnterpriseDefaultVersion}/github`,
9292
title: 'GitHub.com'
9393
}
9494
}
@@ -99,11 +99,11 @@ describe('breadcrumbs', () => {
9999
const breadcrumbs = await getJSON('/en/github/authenticating-to-github?json=breadcrumbs')
100100
const expected = {
101101
product: {
102-
href: `/${nonEnterpriseDefaultVersion}/github`,
102+
href: `/en/${nonEnterpriseDefaultVersion}/github`,
103103
title: 'GitHub.com'
104104
},
105105
category: {
106-
href: `/${nonEnterpriseDefaultVersion}/github/authenticating-to-github`,
106+
href: `/en/${nonEnterpriseDefaultVersion}/github/authenticating-to-github`,
107107
title: 'Authentication'
108108
}
109109
}
@@ -114,15 +114,15 @@ describe('breadcrumbs', () => {
114114
const breadcrumbs = await getJSON('/en/github/authenticating-to-github/keeping-your-account-and-data-secure?json=breadcrumbs')
115115
const expected = {
116116
product: {
117-
href: `/${nonEnterpriseDefaultVersion}/github`,
117+
href: `/en/${nonEnterpriseDefaultVersion}/github`,
118118
title: 'GitHub.com'
119119
},
120120
category: {
121-
href: `/${nonEnterpriseDefaultVersion}/github/authenticating-to-github`,
121+
href: `/en/${nonEnterpriseDefaultVersion}/github/authenticating-to-github`,
122122
title: 'Authentication'
123123
},
124124
maptopic: {
125-
href: `/${nonEnterpriseDefaultVersion}/github/authenticating-to-github/keeping-your-account-and-data-secure`,
125+
href: `/en/${nonEnterpriseDefaultVersion}/github/authenticating-to-github/keeping-your-account-and-data-secure`,
126126
title: 'Keeping your account and data secure'
127127
}
128128
}
@@ -133,19 +133,19 @@ describe('breadcrumbs', () => {
133133
const breadcrumbs = await getJSON('/en/github/authenticating-to-github/creating-a-strong-password?json=breadcrumbs')
134134
const expected = {
135135
product: {
136-
href: `/${nonEnterpriseDefaultVersion}/github`,
136+
href: `/en/${nonEnterpriseDefaultVersion}/github`,
137137
title: 'GitHub.com'
138138
},
139139
category: {
140-
href: `/${nonEnterpriseDefaultVersion}/github/authenticating-to-github`,
140+
href: `/en/${nonEnterpriseDefaultVersion}/github/authenticating-to-github`,
141141
title: 'Authentication'
142142
},
143143
maptopic: {
144-
href: `/${nonEnterpriseDefaultVersion}/github/authenticating-to-github/keeping-your-account-and-data-secure`,
144+
href: `/en/${nonEnterpriseDefaultVersion}/github/authenticating-to-github/keeping-your-account-and-data-secure`,
145145
title: 'Keeping your account and data secure'
146146
},
147147
article: {
148-
href: `/${nonEnterpriseDefaultVersion}/github/authenticating-to-github/creating-a-strong-password`,
148+
href: `/en/${nonEnterpriseDefaultVersion}/github/authenticating-to-github/creating-a-strong-password`,
149149
title: 'Creating a strong password'
150150
}
151151
}
@@ -156,15 +156,15 @@ describe('breadcrumbs', () => {
156156
const breadcrumbs = await getJSON('/github/site-policy/github-privacy-statement?json=breadcrumbs')
157157
const expected = {
158158
product: {
159-
href: `/${nonEnterpriseDefaultVersion}/github`,
159+
href: `/en/${nonEnterpriseDefaultVersion}/github`,
160160
title: 'GitHub.com'
161161
},
162162
category: {
163-
href: `/${nonEnterpriseDefaultVersion}/github/site-policy`,
163+
href: `/en/${nonEnterpriseDefaultVersion}/github/site-policy`,
164164
title: 'Site policy'
165165
},
166166
article: {
167-
href: `/${nonEnterpriseDefaultVersion}/github/site-policy/github-privacy-statement`,
167+
href: `/en/${nonEnterpriseDefaultVersion}/github/site-policy/github-privacy-statement`,
168168
title: 'GitHub Privacy Statement'
169169
}
170170
}

0 commit comments

Comments
 (0)