Skip to content

Commit d8db215

Browse files
authored
repo sync
2 parents eccd18a + 5705d33 commit d8db215

File tree

8 files changed

+118
-76
lines changed

8 files changed

+118
-76
lines changed

.github/workflows/check-all-english-links.yml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,11 @@ jobs:
1818
run: npm run build
1919
- name: Run script
2020
run: script/check-english-links.js > broken_links.md
21-
- name: Check if any broken links
21+
- if: ${{ failure() }}
22+
name: Get title for issue
2223
id: check
23-
run: |
24-
if [ "$(grep '0 broken links found' broken_links.md)" ]; then
25-
echo ::set-output name=continue::no
26-
else
27-
echo "::set-output name=continue::yes"
28-
echo "::set-output name=title::$(head -1 broken_links.md)"
29-
fi
30-
- if: ${{ steps.check.outputs.continue == 'yes' }}
24+
run: echo "::set-output name=title::$(head -1 broken_links.md)"
25+
- if: ${{ failure() }}
3126
name: Create issue from file
3227
uses: peter-evans/create-issue-from-file@35e304e2a12caac08c568247a2cb46ecd0c3ecc5
3328
with:

includes/header-notification.html

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,37 @@
1+
<!-- START TRANSLATIONS NOTICES -->
2+
<!-- Site policy translations notice -->
3+
{% if currentLanguage != 'en' and page.relativePath contains '/site-policy/' %}
4+
{% assign translation_notification_type = "true" %}
5+
{% assign translation_notification = site.data.reusables.policies.translation %}
6+
7+
<!-- Completed translations notice -->
8+
{% elsif currentLanguage != 'en' && !languages[currentLanguage].wip %}
9+
{% assign translation_notification_type = "true" %}
10+
{% assign translation_notification = site.data.ui.header.notices.localization_complete %}
11+
12+
<!-- In-progress translations notice -->
13+
{% elsif currentLanguage != 'en' && languages[currentLanguage].wip %}
14+
{% assign translation_notification_type = "true" %}
15+
{% assign translation_notification = site.data.ui.header.notices.localization_in_progress %}
16+
{% endif %}
17+
<!-- END TRANSLATIONS NOTICES -->
18+
19+
<!-- START RELEASE NOTICES -->
20+
<!-- Custom GitHub AE notice -->
121
{% if currentVersion == "github-ae@latest" %}
2-
<div class="header-notifications text-center f5 bg-blue-1 text-gray-dark py-4 px-6 limited_release {% if header_notification %}border-bottom{% endif %}">
3-
{% data ui.header.notices.ghae_silent_launch %}
22+
{% assign release_notification_type = "true" %}
23+
{% assign release_notification = site.data.ui.header.notices.ghae_silent_launch %}
24+
{% endif %}
25+
<!-- END RELEASE NOTICES -->
26+
27+
{% if translation_notification_type %}
28+
<div class="header-notifications text-center f5 bg-blue-1 text-gray-dark py-4 px-6 translation_notice{% if release_notification_type %} border-bottom border-black-fade{% endif %}">
29+
{{ translation_notification }}
430
</div>
531
{% endif %}
632

7-
{% if header_notification %}
8-
<div class="header-notifications text-center f5 bg-blue-1 text-gray-dark py-4 px-6 {{ header_notification_type }}">
9-
{{ header_notification }}
33+
{% if release_notification_type %}
34+
<div class="header-notifications text-center f5 bg-blue-1 text-gray-dark py-4 px-6 release_notice">
35+
{{ release_notification }}
1036
</div>
1137
{% endif %}

includes/header.html

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,4 @@
11
<div class="border-bottom border-gray-light no-print">
2-
3-
{% if currentLanguage != 'en' and page.relativePath contains '/site-policy/' %}
4-
{% assign header_notification_type = "translation_policy" %}
5-
{% assign header_notification = site.data.reusables.policies.translation %}
6-
7-
{% elsif site.data.ui.header.notices.flags.localization_complete == true %}
8-
{% assign header_notification_type = "localization_complete" %}
9-
{% assign header_notification = site.data.ui.header.notices.localization_complete %}
10-
11-
{% elsif site.data.ui.header.notices.flags.localization_in_progress == true %}
12-
{% assign header_notification_type = "localization_in_progress" %}
13-
{% assign header_notification = site.data.ui.header.notices.localization_in_progress %}
14-
15-
{% elsif currentLanguage == 'en' and site.data.ui.header.notices.flags.product_in_progress == true %}
16-
{% assign header_notification_type = "product_in_progress" %}
17-
{% assign header_notification = site.data.ui.header.notices.product_in_progress %}
18-
{% endif %}
19-
202
{% include header-notification %}
213

224
<header class="container-xl px-3 px-md-6 pt-3 pb-2 position-relative d-flex flex-justify-between width-full {% if error == '404' %} d-md-none {% endif %}">

middleware/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ module.exports = function (app) {
4242
app.use(require('./early-access-paths'))
4343
app.use(require('./early-access-proxy'))
4444
app.use(require('./find-page'))
45-
app.use(require('./notices'))
4645
app.use(require('./archived-enterprise-versions'))
4746
app.use(require('./archived-enterprise-versions-assets'))
4847
app.use('/assets', express.static('assets'))

middleware/notices.js

Lines changed: 0 additions & 38 deletions
This file was deleted.

script/content-migrations/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Content migration scripts
2+
3+
This directory stores scripts that modify content and/or data files. Because
4+
writers are updating content all the time, scripts in here require more
5+
cross-team coordination and planning before they are run. Make sure to consider
6+
whether a script added here also needs to be run on translation files or if we
7+
can wait for the changes to come in organically via Crowdin.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/env node
2+
3+
const fs = require('fs')
4+
const path = require('path')
5+
const walk = require('walk-sync')
6+
const frontmatter = require('@github-docs/frontmatter')
7+
const loadPages = require('../../lib/pages')
8+
const patterns = require('../../lib/patterns')
9+
const loadRedirects = require('../../lib/redirects/precompile')
10+
const allVersions = Object.keys(require('../../lib/all-versions'))
11+
12+
// get all content and data files
13+
const files = ['content', 'data'].map(dir => {
14+
return walk(path.join(process.cwd(), dir), { includeBasePath: true, directories: false })
15+
.filter(file => file.endsWith('.md') && !file.endsWith('README.md'))
16+
}).flat()
17+
18+
// match [foo](/v3) and [bar](/v4) Markdown links
19+
const linkRegex = new RegExp('\\(/v[34].*?\\)', 'g')
20+
21+
main()
22+
23+
async function main () {
24+
// we need to load the pages so we can get the redirects
25+
const englishPages = (await loadPages()).filter(p => p.languageCode === 'en')
26+
const redirects = await loadRedirects(englishPages)
27+
28+
for (const file of files) {
29+
const { data, content } = frontmatter(fs.readFileSync(file, 'utf8'))
30+
31+
const links = content.match(linkRegex)
32+
if (!links) continue
33+
34+
// remove parentheses: (/v3) -> /v3
35+
// also remove trailing slash before closing parens if there is one
36+
const devLinks = links
37+
.map(link => link.replace('(', '').replace(/\/?\)/, ''))
38+
39+
let newContent = content
40+
41+
for (const devLink of devLinks) {
42+
const [link, fragment] = devLink.split(/\/?#/)
43+
44+
let redirect = redirects[link]
45+
46+
if (!redirect) {
47+
console.log(`no redirect found for ${devLink} in ${file}`)
48+
continue
49+
}
50+
51+
// do some cleanup
52+
redirect = redirect
53+
// remove language code segment
54+
.replace(patterns.getLanguageCode, '')
55+
// remove version segment
56+
.replace(new RegExp(`/(${allVersions.join('|')})`), '')
57+
58+
// re-add the fragment
59+
const newLink = fragment
60+
? redirect + '#' + fragment
61+
: redirect
62+
63+
// first remove any trailing slashes from the old link,
64+
// then replace with the new link
65+
newContent = newContent
66+
.replace(`${devLink}/`, devLink)
67+
.replace(devLink, newLink)
68+
}
69+
70+
fs.writeFileSync(file, frontmatter.stringify(newContent, data, { lineWidth: 10000 }))
71+
}
72+
console.log('Done!')
73+
}

tests/rendering/header.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,13 @@ describe('header', () => {
4242
describe('notices', () => {
4343
test('displays a "localization in progress" notice for WIP languages', async () => {
4444
const $ = await getDOM('/de')
45-
expect($('.header-notifications.localization_in_progress').length).toBe(1)
46-
expect($('.localization_complete').length).toBe(0)
45+
expect($('.header-notifications.translation_notice').length).toBe(1)
4746
expect($('.header-notifications a[href="/en"]').length).toBe(1)
4847
})
4948

5049
test('displays "complete" notice for non-WIP non-English languages', async () => {
5150
const $ = await getDOM('/ja')
52-
expect($('.header-notifications.localization_complete').length).toBe(1)
53-
expect($('.localization_in_progress').length).toBe(0)
51+
expect($('.header-notifications.translation_notice').length).toBe(1)
5452
expect($('.header-notifications a[href="/en"]').length).toBe(1)
5553
expect($('.header-notifications a[href*="github.com/contact"]').length).toBe(1)
5654
})
@@ -62,7 +60,7 @@ describe('header', () => {
6260

6361
test('displays translation disclaimer notice on localized site-policy pages', async () => {
6462
const $ = await getDOM('/ja/github/site-policy/github-logo-policy')
65-
expect($('.header-notifications.translation_policy a[href="https://github.com/github/site-policy/issues"]').length).toBe(1)
63+
expect($('.header-notifications.translation_notice a[href="https://github.com/github/site-policy/issues"]').length).toBe(1)
6664
})
6765
})
6866

0 commit comments

Comments
 (0)