Skip to content

Commit

Permalink
repo sync
Browse files Browse the repository at this point in the history
  • Loading branch information
Octomerger authored Nov 12, 2020
2 parents eccd18a + 5705d33 commit d8db215
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 76 deletions.
13 changes: 4 additions & 9 deletions .github/workflows/check-all-english-links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,11 @@ jobs:
run: npm run build
- name: Run script
run: script/check-english-links.js > broken_links.md
- name: Check if any broken links
- if: ${{ failure() }}
name: Get title for issue
id: check
run: |
if [ "$(grep '0 broken links found' broken_links.md)" ]; then
echo ::set-output name=continue::no
else
echo "::set-output name=continue::yes"
echo "::set-output name=title::$(head -1 broken_links.md)"
fi
- if: ${{ steps.check.outputs.continue == 'yes' }}
run: echo "::set-output name=title::$(head -1 broken_links.md)"
- if: ${{ failure() }}
name: Create issue from file
uses: peter-evans/create-issue-from-file@35e304e2a12caac08c568247a2cb46ecd0c3ecc5
with:
Expand Down
36 changes: 31 additions & 5 deletions includes/header-notification.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
<!-- START TRANSLATIONS NOTICES -->
<!-- Site policy translations notice -->
{% if currentLanguage != 'en' and page.relativePath contains '/site-policy/' %}
{% assign translation_notification_type = "true" %}
{% assign translation_notification = site.data.reusables.policies.translation %}

<!-- Completed translations notice -->
{% elsif currentLanguage != 'en' && !languages[currentLanguage].wip %}
{% assign translation_notification_type = "true" %}
{% assign translation_notification = site.data.ui.header.notices.localization_complete %}

<!-- In-progress translations notice -->
{% elsif currentLanguage != 'en' && languages[currentLanguage].wip %}
{% assign translation_notification_type = "true" %}
{% assign translation_notification = site.data.ui.header.notices.localization_in_progress %}
{% endif %}
<!-- END TRANSLATIONS NOTICES -->

<!-- START RELEASE NOTICES -->
<!-- Custom GitHub AE notice -->
{% if currentVersion == "github-ae@latest" %}
<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 %}">
{% data ui.header.notices.ghae_silent_launch %}
{% assign release_notification_type = "true" %}
{% assign release_notification = site.data.ui.header.notices.ghae_silent_launch %}
{% endif %}
<!-- END RELEASE NOTICES -->

{% if translation_notification_type %}
<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 %}">
{{ translation_notification }}
</div>
{% endif %}

{% if header_notification %}
<div class="header-notifications text-center f5 bg-blue-1 text-gray-dark py-4 px-6 {{ header_notification_type }}">
{{ header_notification }}
{% if release_notification_type %}
<div class="header-notifications text-center f5 bg-blue-1 text-gray-dark py-4 px-6 release_notice">
{{ release_notification }}
</div>
{% endif %}
18 changes: 0 additions & 18 deletions includes/header.html
Original file line number Diff line number Diff line change
@@ -1,22 +1,4 @@
<div class="border-bottom border-gray-light no-print">

{% if currentLanguage != 'en' and page.relativePath contains '/site-policy/' %}
{% assign header_notification_type = "translation_policy" %}
{% assign header_notification = site.data.reusables.policies.translation %}

{% elsif site.data.ui.header.notices.flags.localization_complete == true %}
{% assign header_notification_type = "localization_complete" %}
{% assign header_notification = site.data.ui.header.notices.localization_complete %}

{% elsif site.data.ui.header.notices.flags.localization_in_progress == true %}
{% assign header_notification_type = "localization_in_progress" %}
{% assign header_notification = site.data.ui.header.notices.localization_in_progress %}

{% elsif currentLanguage == 'en' and site.data.ui.header.notices.flags.product_in_progress == true %}
{% assign header_notification_type = "product_in_progress" %}
{% assign header_notification = site.data.ui.header.notices.product_in_progress %}
{% endif %}

{% include header-notification %}

<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 %}">
Expand Down
1 change: 0 additions & 1 deletion middleware/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ module.exports = function (app) {
app.use(require('./early-access-paths'))
app.use(require('./early-access-proxy'))
app.use(require('./find-page'))
app.use(require('./notices'))
app.use(require('./archived-enterprise-versions'))
app.use(require('./archived-enterprise-versions-assets'))
app.use('/assets', express.static('assets'))
Expand Down
38 changes: 0 additions & 38 deletions middleware/notices.js

This file was deleted.

7 changes: 7 additions & 0 deletions script/content-migrations/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Content migration scripts

This directory stores scripts that modify content and/or data files. Because
writers are updating content all the time, scripts in here require more
cross-team coordination and planning before they are run. Make sure to consider
whether a script added here also needs to be run on translation files or if we
can wait for the changes to come in organically via Crowdin.
73 changes: 73 additions & 0 deletions script/content-migrations/update-developer-site-links.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/usr/bin/env node

const fs = require('fs')
const path = require('path')
const walk = require('walk-sync')
const frontmatter = require('@github-docs/frontmatter')
const loadPages = require('../../lib/pages')
const patterns = require('../../lib/patterns')
const loadRedirects = require('../../lib/redirects/precompile')
const allVersions = Object.keys(require('../../lib/all-versions'))

// get all content and data files
const files = ['content', 'data'].map(dir => {
return walk(path.join(process.cwd(), dir), { includeBasePath: true, directories: false })
.filter(file => file.endsWith('.md') && !file.endsWith('README.md'))
}).flat()

// match [foo](/v3) and [bar](/v4) Markdown links
const linkRegex = new RegExp('\\(/v[34].*?\\)', 'g')

main()

async function main () {
// we need to load the pages so we can get the redirects
const englishPages = (await loadPages()).filter(p => p.languageCode === 'en')
const redirects = await loadRedirects(englishPages)

for (const file of files) {
const { data, content } = frontmatter(fs.readFileSync(file, 'utf8'))

const links = content.match(linkRegex)
if (!links) continue

// remove parentheses: (/v3) -> /v3
// also remove trailing slash before closing parens if there is one
const devLinks = links
.map(link => link.replace('(', '').replace(/\/?\)/, ''))

let newContent = content

for (const devLink of devLinks) {
const [link, fragment] = devLink.split(/\/?#/)

let redirect = redirects[link]

if (!redirect) {
console.log(`no redirect found for ${devLink} in ${file}`)
continue
}

// do some cleanup
redirect = redirect
// remove language code segment
.replace(patterns.getLanguageCode, '')
// remove version segment
.replace(new RegExp(`/(${allVersions.join('|')})`), '')

// re-add the fragment
const newLink = fragment
? redirect + '#' + fragment
: redirect

// first remove any trailing slashes from the old link,
// then replace with the new link
newContent = newContent
.replace(`${devLink}/`, devLink)
.replace(devLink, newLink)
}

fs.writeFileSync(file, frontmatter.stringify(newContent, data, { lineWidth: 10000 }))
}
console.log('Done!')
}
8 changes: 3 additions & 5 deletions tests/rendering/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,13 @@ describe('header', () => {
describe('notices', () => {
test('displays a "localization in progress" notice for WIP languages', async () => {
const $ = await getDOM('/de')
expect($('.header-notifications.localization_in_progress').length).toBe(1)
expect($('.localization_complete').length).toBe(0)
expect($('.header-notifications.translation_notice').length).toBe(1)
expect($('.header-notifications a[href="/en"]').length).toBe(1)
})

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

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

Expand Down

0 comments on commit d8db215

Please sign in to comment.