1
0
mirror of synced 2026-01-05 12:07:35 -05:00

Merge pull request #21488 from github/repo-sync

repo sync
This commit is contained in:
Octomerger Bot
2022-10-19 09:25:39 -07:00
committed by GitHub
6 changed files with 528 additions and 416 deletions

View File

@@ -39,28 +39,98 @@ Usage: script/anonymize-branch.js <new-commit-message> [base-branch] Example: sc
---
### [`check-english-links.js`](check-english-links.js)
### [`bookmarklets/add-pr-links.js`](bookmarklets/add-pr-links.js)
---
### [`bookmarklets/open-in-vscode.js`](bookmarklets/open-in-vscode.js)
---
### [`bookmarklets/pr-link-source.js`](bookmarklets/pr-link-source.js)
---
### [`bookmarklets/view-in-development.js`](bookmarklets/view-in-development.js)
---
### [`bookmarklets/view-in-production.js`](bookmarklets/view-in-production.js)
This script runs once per day via a scheduled GitHub Action to check all links in English content, not including deprecated Enterprise Server content. It opens an issue if it finds broken links. To exclude a link path, add it to `lib/excluded-links.js`.
---
### [`check-for-node`](check-for-node)
This script is run automatically when you run the server locally. It checks whether or not Node.js is installed.
This script is run automatically when you run the server locally. It checks whether Node.js is installed.
---
### [`content-migrations/extended-markdown-tags.js`](content-migrations/extended-markdown-tags.js)
### [`check-github-github-links.js`](check-github-github-links.js)
Run this script to get all broken docs.github.com links in github/github
---
### [`content-migrations/add-early-access-tocs.js`](content-migrations/add-early-access-tocs.js)
---
### [`content-migrations/octicon-tag.js`](content-migrations/octicon-tag.js)
### [`content-migrations/add-ghec-to-schema.js`](content-migrations/add-ghec-to-schema.js)
A one-time use script to add GHEC to the REST schema on github/github.
---
### [`content-migrations/add_mini_toc_frontmatter.js`](content-migrations/add_mini_toc_frontmatter.js)
Run this one time script to add max mini toc to rest reference documentation
---
### [`content-migrations/comment-on-open-prs.js`](content-migrations/comment-on-open-prs.js)
This script finds all open PRs from active branches that touch content files, and adds a comment with steps to run some commands. The idea is to help writers and other Hubbers update their open branches and mitigate conflicts with the main branch.
---
### [`content-migrations/convert-if-to-ifversion.js`](content-migrations/convert-if-to-ifversion.js)
Run this one-time script to convert `if <feature name>` Liquid tags to `ifversion <feature name>`.
---
### [`content-migrations/create-csv-of-short-titles.js`](content-migrations/create-csv-of-short-titles.js)
---
### [`content-migrations/move-unique-image-assets.js`](content-migrations/move-unique-image-assets.js)
@@ -74,7 +144,14 @@ This script is run automatically when you run the server locally. It checks whet
---
### [`content-migrations/site-data-tag.js`](content-migrations/site-data-tag.js)
### [`content-migrations/remove-unused-assets.js`](content-migrations/remove-unused-assets.js)
---
### [`content-migrations/topics-upcase.js`](content-migrations/topics-upcase.js)
@@ -88,17 +165,72 @@ This script is run automatically when you run the server locally. It checks whet
---
### [`create-glossary-from-spreadsheet.js`](create-glossary-from-spreadsheet.js)
### [`content-migrations/update-headers.js`](content-migrations/update-headers.js)
Run this one time script to update headers for accessibility Changing H3 to H2, H4 to H3, H5 to H4, and H6 to H5
---
### [`content-migrations/update-versioning-in-files.js`](content-migrations/update-versioning-in-files.js)
This script turns a Google Sheets CSV spreadsheet into a YAML file.
---
### [`early-access/clone-for-build.js`](early-access/clone-for-build.js)
### [`content-migrations/use-short-versions.js`](content-migrations/use-short-versions.js)
Run this script to convert long form Liquid conditionals (e.g., {% if currentVersion == "free-pro-team" %}) to the new custom tag (e.g., {% ifversion fpt %}) and also use the short names in versions frontmatter.
---
### [`copy-to-test-repo.sh`](copy-to-test-repo.sh)
---
### [`create-glossary-from-spreadsheet.js`](create-glossary-from-spreadsheet.js)
This script turns a Google Sheets CSV spreadsheet into a YAML file.
---
### [`deployment/purge-edge-cache.js`](deployment/purge-edge-cache.js)
---
### [`dev-toc/generate.js`](dev-toc/generate.js)
---
### [`dev-toc/index.js`](dev-toc/index.js)
---
### [`dev-toc/layout.html`](dev-toc/layout.html)
---
### [`domwaiter.js`](domwaiter.js)
This script is run as a postbuild script during staging and deployments on Heroku. It clones a branch in the early-access repo that matches the current branch in the docs repo; if one can't be found, it clones the `main` branch.
---
@@ -135,6 +267,21 @@ This script is run on a writer's machine while developing Early Access content l
Run this script during the Enterprise deprecation process to download static copies of all pages for the oldest supported Enterprise version. See the Enterprise deprecation issue template for instructions.
NOTE: If you get this error:
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'website-scraper' ...
it's because you haven't installed all the *optional* dependencies. To do that, run:
npm install --include=optional
---
### [`enterprise-server-deprecations/remove-redirects.js`](enterprise-server-deprecations/remove-redirects.js)
Run this script after an Enterprise deprecation to remove redirects for the deprecated version. See the Enterprise deprecation issue template for instructions.
---
@@ -152,6 +299,13 @@ Run this script after an Enterprise deprecation to remove Liquid statements and
---
### [`enterprise-server-releases/add-ghec-to-fpt.js`](enterprise-server-releases/add-ghec-to-fpt.js)
Run this script to add versions frontmatter and Liquid conditionals for GitHub Enterprise Cloud, based on anything currently versioned for the specified release of free-pro-team.
---
### [`enterprise-server-releases/create-graphql-files.js`](enterprise-server-releases/create-graphql-files.js)
This script creates the static GraphQL files for a new version.
@@ -161,7 +315,7 @@ This script creates the static GraphQL files for a new version.
### [`enterprise-server-releases/create-rest-files.js`](enterprise-server-releases/create-rest-files.js)
This script creates new static openAPI files for a new version and modifies the info.version.
This script first copies the dereferenced schema from the previous GHES version for the new one. It then replaces references to the previous version's docs URL (e.g., enterprise-server@3.0) with the new version (e.g., enterprise-server@3.1). Finally, it generates a new decorated file from the new dereferenced file to ensure that the dereferenced and decorated files match.
---
@@ -175,7 +329,7 @@ This script creates new static webhook payload files for a new version.
### [`enterprise-server-releases/ghes-to-ghae-versioning.js`](enterprise-server-releases/ghes-to-ghae-versioning.js)
Run this script to add versions frontmatter and Liquid conditionals for GitHub AE, based on anything currently versioned for the provided release of Enterprise Server. This script should be run as part of the Enterprise Server release process.
Run this script to add versions frontmatter and Liquid conditionals for GitHub AE, based on anything currently versioned for the specified release of Enterprise Server. This script should be run as part of the Enterprise Server release process.
---
@@ -187,22 +341,16 @@ This script creates or removes a release candidate banner for a specified versio
---
### [`get-new-dotcom-path.js`](get-new-dotcom-path.js)
### [`find-orphaned-assets.js`](find-orphaned-assets.js)
Pass this script any old dotcom path (e.g., `articles/foo` or `foo.md`) and it will output the new path in the content/github directory.
Print a list of all the asset files that can't be found mentioned in any of the source files (content & code).
---
### [`get-new-version-path.js`](get-new-version-path.js)
### [`get-new-dotcom-path.js`](get-new-dotcom-path.js)
Helper script that returns a "new" versioned path given an "old" versioned path.
Examples:
Given: /github/getting-started-with-github/using-github Returns: /free-pro-team@latest/github/getting-started-with-github/using-github
Given: /enterprise/admin/installation/upgrading-github-enterprise Returns: /enterprise-server@2.22/admin/installation/upgrading-github-enterprise
Pass this script any old dotcom path (e.g., `articles/foo` or `foo.md`) and it will output the new path in the content/github directory.
---
@@ -225,13 +373,6 @@ Given: /enterprise/admin/installation/upgrading-github-enterprise Returns: /ente
---
### [`graphql/utils/prerender-objects.js`](graphql/utils/prerender-objects.js)
---
@@ -252,6 +393,7 @@ Given: /enterprise/admin/installation/upgrading-github-enterprise Returns: /ente
### [`graphql/utils/process-upcoming-changes.js`](graphql/utils/process-upcoming-changes.js)
---
@@ -259,6 +401,170 @@ Given: /enterprise/admin/installation/upgrading-github-enterprise Returns: /ente
---
### [`helpers/action-injections.js`](helpers/action-injections.js)
---
### [`helpers/add-redirect-to-frontmatter.js`](helpers/add-redirect-to-frontmatter.js)
---
### [`helpers/find-unused-assets.js`](helpers/find-unused-assets.js)
---
### [`helpers/get-liquid-conditionals.js`](helpers/get-liquid-conditionals.js)
---
### [`helpers/get-version-blocks.js`](helpers/get-version-blocks.js)
---
### [`helpers/git-utils.js`](helpers/git-utils.js)
---
### [`helpers/github.js`](helpers/github.js)
---
### [`helpers/remove-deprecated-frontmatter.js`](helpers/remove-deprecated-frontmatter.js)
---
### [`helpers/remove-liquid-statements.js`](helpers/remove-liquid-statements.js)
---
### [`helpers/retry-on-error-test.js`](helpers/retry-on-error-test.js)
Return a function that you can use to run any code within and if it throws you get a chance to say whether to sleep + retry. Example:
async function mainFunction() { if (Math.random() > 0.9) throw new Error('too large') return 'OK' }
const errorTest = (err) => err instanceof Error && err.message.includes('too large') const config = { // all optional attempts: 3, sleepTime: 800, onError: (err, attempts) => console.warn(`Failed ${attempts} attempts`) } const ok = await retry(errorTest, mainFunction, config)
---
### [`helpers/walk-files.js`](helpers/walk-files.js)
A helper that returns an array of files for a given path and file extension.
---
### [`i18n/fix-translation-errors.js`](i18n/fix-translation-errors.js)
Run this script to fix known frontmatter errors by copying values from english file Currently only fixing errors in: 'type', 'changelog' Please double check the changes created by this script before committing.
---
### [`i18n/homogenize-frontmatter.js`](i18n/homogenize-frontmatter.js)
Run this script to fix known frontmatter errors by copying values from english file Translatable properties are designated in the frontmatter JSON schema
---
### [`i18n/lint-translation-files.js`](i18n/lint-translation-files.js)
Use this script as part of the translation merge process to output a list of either parsing or rendering errors in translated files and run script/i18n/reset-translated-file.js on them.
---
### [`i18n/msft-report-reset-files.js`](i18n/msft-report-reset-files.js)
---
### [`i18n/msft-reset-files-with-broken-liquid-tags.js`](i18n/msft-reset-files-with-broken-liquid-tags.js)
---
### [`i18n/msft-tokens.js`](i18n/msft-tokens.js)
---
### [`i18n/prune-stale-files.js`](i18n/prune-stale-files.js)
---
### [`i18n/reset-translated-file.js`](i18n/reset-translated-file.js)
This is a convenience script for replacing the contents of translated files with the English content from their corresponding source file.
Usage: script/i18n/reset-translated-file.js <filename>
Examples:
$ script/i18n/reset-translated-file.js translations/es-XL/content/actions/index.md
---
### [`i18n/test-html-pages.js`](i18n/test-html-pages.js)
---
### [`i18n/test-render-translation.js`](i18n/test-render-translation.js)
Run this script to test-render all the translation files that have been changed (when compared to the `main` branch).
---
### [`kill-server-for-jest.js`](kill-server-for-jest.js)
---
@@ -266,12 +572,34 @@ Given: /enterprise/admin/installation/upgrading-github-enterprise Returns: /ente
This script lists all local image files, sorted by their dimensions.
NOTE: If you get this error:
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'image-size' ...
it's because you haven't installed all the *optional* dependencies. To do that, run:
npm install --include=optional
---
### [`migrate-colors-primer-18.js`](migrate-colors-primer-18.js)
---
### [`move-category-to-product.js`](move-category-to-product.js)
Pass this script three arguments: 1. current category path (e.g., `github/automating-your-workflows-with-github-actions`) 2. new product ID (e.g., `actions`) 3. new product name in quotes (e.g., `"GitHub Actions"`) and it does everything that needs to be done to make the category into a new product.
Move the files from a category directory to a top-level product and add redirects.
---
### [`move-content.js`](move-content.js)
Helps you move (a.k.a. rename) a file or a folder and does what's needed with frontmatter redrect_from and equivalent in translations.
---
@@ -290,13 +618,6 @@ This is a temporary script to visualize which pages have liquid (and conditional
---
### [`ping-staging-apps.js`](ping-staging-apps.js)
This script finds all Heroku staging apps and pings them to make sure they're always "warmed" and responsive to requests.
---
### [`prevent-pushes-to-main.js`](prevent-pushes-to-main.js)
This script is intended to be used as a git "prepush" hook. If the current branch is main, it will exit unsuccessfully and prevent the push.
@@ -306,7 +627,7 @@ This script is intended to be used as a git "prepush" hook. If the current branc
### [`prevent-translation-commits.js`](prevent-translation-commits.js)
This script is run as a git precommit hook (installed by husky after npm install). It detects changes to the files in the translations folder and prevents the commit if any changes exist.
This script is run as a git precommit hook (installed by husky after npm install). It detects changes to files the in the translations folder and prevents the commit if any changes exist.
---
@@ -345,13 +666,6 @@ An automated test checks for discrepancies between filenames and [autogenerated
---
### [`remove-stale-staging-apps.js`](remove-stale-staging-apps.js)
This script removes all stale Heroku staging apps that outlasted the closure of their corresponding pull requests, or correspond to spammy pull requests.
---
### [`remove-unused-assets.js`](remove-unused-assets.js)
Run this script to remove reusables and image files that exist in the repo but are not used in content files. It also displays a list of unused variables. Set the `--dry-run` to flag to print results without deleting any files. For images you don't want to delete, add them to `ignoreList` in `lib/find-unused-assets.js`
@@ -359,21 +673,23 @@ Run this script to remove reusables and image files that exist in the repo but a
---
### [`reset-translated-file.js`](reset-translated-file.js)
### [`rendered-content-link-checker.js`](rendered-content-link-checker.js)
This is a convenience script for replacing the contents of translated files with the English content from their corresponding source file.
This script goes through all content and renders their HTML and from there can analyze for various flaws (e.g. broken links)
Usage: script/i18n/reset-translated-file.js <filename>
---
Examples:
reset a single translated file using a relative path: $ script/i18n/reset-translated-file.js translations/es-XL/content/actions/index.md
### [`rest/openapi-check.js`](rest/openapi-check.js)
reset a single translated file using a full path: $ script/i18n/reset-translated-file.js /Users/z/git/github/docs-internal/translations/es-XL/content/actions/index.md
Run this script to check if OpenAPI files can be decorated successfully.
reset all language variants of a single English file (using a relative path): $ script/i18n/reset-translated-file.js content/actions/index.md $ script/i18n/reset-translated-file.js data/ui.yml
---
reset all language variants of a single English file (using a full path): $ script/i18n/reset-translated-file.js /Users/z/git/github/docs-internal/content/desktop/index.md $ script/i18n/reset-translated-file.js /Users/z/git/github/docs-internal/data/ui.yml
### [`rest/test-open-api-schema.js`](rest/test-open-api-schema.js)
Run this script to check if OpenAPI operations match versions in content/rest operations
---
@@ -385,7 +701,21 @@ Run this script to pull openAPI files from github/github, dereference them, and
---
### [`rest/utils/create-code-samples.js`](rest/utils/create-code-samples.js)
### [`rest/utils/create-rest-examples.js`](rest/utils/create-rest-examples.js)
---
### [`rest/utils/decorator.js`](rest/utils/decorator.js)
---
### [`rest/utils/get-body-params.js`](rest/utils/get-body-params.js)
@@ -413,7 +743,125 @@ Run this script to pull openAPI files from github/github, dereference them, and
---
### [`sample-unix-commands.md`](sample-unix-commands.md)
### [`rest/utils/rest-api-overrides.json`](rest/utils/rest-api-overrides.json)
---
### [`rest/utils/webhook-schema.js`](rest/utils/webhook-schema.js)
---
### [`rest/utils/webhook.js`](rest/utils/webhook.js)
---
### [`search/analyze-text.js`](search/analyze-text.js)
See how a piece of text gets turned into tokens by the different analyzers. Requires that the index exists in Elasticsearch.
Example:
./script/search/analyze-text.js my words to tokenize
---
### [`search/build-records.js`](search/build-records.js)
---
### [`search/find-indexable-pages.js`](search/find-indexable-pages.js)
---
### [`search/index-elasticsearch.js`](search/index-elasticsearch.js)
Creates Elasticsearch index, populates from records, moves the index alias, deletes old indexes.
---
### [`search/lunr-get-index-names.js`](search/lunr-get-index-names.js)
---
### [`search/lunr-search-index.js`](search/lunr-search-index.js)
---
### [`search/parse-page-sections-into-records.js`](search/parse-page-sections-into-records.js)
---
### [`search/popular-pages.js`](search/popular-pages.js)
---
### [`search/search-index-records.js`](search/search-index-records.js)
---
### [`search/search-qa-data.json`](search/search-qa-data.json)
---
### [`search/search-qa-test.js`](search/search-qa-test.js)
This script is a quality assurance test for the Lunr search configuration. This test runs example queries and expects a specific page to land in the top 3 results.
The data source used by this script is a JSON file `script/search/search-qa-data.json`, which is populated from spreadsheet data here: https://docs.google.com/spreadsheets/d/1Dt5JRVcmyAGWKBwGjwmXxi7Ww_vdfYLfZ-EFpu2S2CQ/edit?usp=sharing
---
### [`search/sync-search-indices.js`](search/sync-search-indices.js)
This script is run automatically via GitHub Actions on every push to `main` to generate searchable data. It can also be run manually. For more info see [contributing/search.md](contributing/search.md)
---
### [`search/sync.js`](search/sync.js)
---
### [`search/validate-records.js`](search/validate-records.js)
@@ -427,6 +875,13 @@ Starts the local development server with all of the available languages enabled.
---
### [`server-for-jest.js`](server-for-jest.js)
---
### [`standardize-frontmatter-order.js`](standardize-frontmatter-order.js)
Run this script to standardize frontmatter fields in all content files, per the order: - title - intro - product callout - productVersion - map topic status - hidden status - layout - redirect
@@ -434,9 +889,9 @@ Run this script to standardize frontmatter fields in all content files, per the
---
### [`sync-search-indices.js`](sync-search-indices.js)
### [`start-server-for-jest.js`](start-server-for-jest.js)
This script is run on a schedule every four hours to generate searchable data. It can also be run manually. To run it manually, click "Run workflow" button in the [Actions tab](https://github.com/github/docs-internal/actions/workflows/sync-search-indices.yml). For more info see [contributing/search.md](contributing/search.md)
---
@@ -448,6 +903,13 @@ List all the TODOs in our JavaScript files and stylesheets.
---
### [`toggle-ghae-feature-flags.js`](toggle-ghae-feature-flags.js)
Find and replace lightweight feature flags for GitHub AE content.
---
### [`update-enterprise-dates.js`](update-enterprise-dates.js)
This script fetches data from https://github.com/github/enterprise-releases/blob/master/releases.json and updates `lib/enterprise-dates.json`, which the site uses for various functionality.
@@ -455,6 +917,15 @@ This script fetches data from https://github.com/github/enterprise-releases/blob
---
### [`update-internal-links.js`](update-internal-links.js)
Run this script to find internal links in all content and data Markdown files, check if either the title or link (or both) are outdated, and automatically update them if so.
Exceptions: * Links with fragments (e.g., [Bar](/foo#bar)) will get their root links updated if necessary, but the fragment and title will be unchanged (e.g., [Bar](/noo#bar)). * Links with hardcoded versions (e.g., [Foo](/enterprise-server/baz)) will get their root links updated if necessary, but the hardcoded versions will be preserved (e.g., [Foo](/enterprise-server/qux)). * Links with Liquid in the titles will have their root links updated if necessary, but the titles will be preserved.
---
### [`update-readme.js`](update-readme.js)
This script crawls the script directory, hooks on special comment markers in each script, and adds the comment to `script/README.md`.
@@ -462,8 +933,3 @@ This script crawls the script directory, hooks on special comment markers in eac
---
### [`update-versioning-in-files.js`](update-versioning-in-files.js)
---

View File

@@ -1,44 +0,0 @@
#!/usr/bin/env node
import { fileURLToPath } from 'url'
import path from 'path'
import walk from 'walk-sync'
import replace from 'replace'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const FINDER = /{{\s?([#/])([a-z-]+)?\s?}}/g
async function rewriteFiles(dir) {
const files = walk(dir, { includeBasePath: true })
replace({
regex: FINDER,
replacement: (match, p1, p2) => {
if (p1 === '#') {
// The starting tag, like {{#note}}
return `{% ${p2} %}`
} else if (p1 === '/') {
// The ending tag, like {{/note}}
return `{% end${p2} %}`
} else {
throw new Error(`Invalid prefix ${p1} found`)
}
},
paths: files,
recursive: true,
})
}
async function main() {
const dirs = [
path.join(__dirname, '../../content'),
path.join(__dirname, '../../data'),
path.join(__dirname, '../../translations'),
]
for (const dir of dirs) {
await rewriteFiles(dir)
}
}
main()
.catch(console.error)
.finally(() => console.log('Done!'))

View File

@@ -1,40 +0,0 @@
#!/usr/bin/env node
import { fileURLToPath } from 'url'
import path from 'path'
import walk from 'walk-sync'
import replace from 'replace'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const FINDER = /{{\s?octicon-([a-z-]+)(\s[\w\s\d-]+)?\s?}}/g
async function rewriteFiles(dir) {
const files = walk(dir, { includeBasePath: true })
replace({
regex: FINDER,
replacement: (match, p1, p2) => {
if (p2) {
return `{% octicon "${p1}" aria-label="${p2.trim()}" %}`
} else {
return `{% octicon "${p1}" %}`
}
},
paths: files,
recursive: true,
})
}
async function main() {
const dirs = [
path.join(__dirname, '../../content'),
path.join(__dirname, '../../data'),
path.join(__dirname, '../../translations'),
]
for (const dir of dirs) {
await rewriteFiles(dir)
}
}
main()
.catch(console.error)
.finally(() => console.log('Done!'))

View File

@@ -1,121 +0,0 @@
#!/usr/bin/env node
import fs from 'fs'
import path from 'path'
import walk from 'walk-sync'
import stripHtmlComments from 'strip-html-comments'
import languages from '../../lib/languages.js'
import frontmatter from '../../lib/read-frontmatter.js'
import addRedirectToFrontmatter from '../helpers/add-redirect-to-frontmatter.js'
const relativeRefRegex = /\/[a-zA-Z0-9-]+/g
const linkString = /{% [^}]*?link.*? \/(.*?) ?%}/m
const linksArray = new RegExp(linkString.source, 'gm')
const walkOpts = {
includeBasePath: true,
directories: false,
}
// We only want category TOC files, not product TOCs.
const categoryFileRegex = /content\/[^/]+?\/[^/]+?\/index.md/
const fullDirectoryPaths = Object.values(languages).map((langObj) =>
path.join(process.cwd(), langObj.dir, 'content')
)
const categoryIndexFiles = fullDirectoryPaths
.map((fullDirectoryPath) => walk(fullDirectoryPath, walkOpts))
.flat()
.filter((file) => categoryFileRegex.test(file))
categoryIndexFiles.forEach((categoryIndexFile) => {
let categoryIndexContent = fs.readFileSync(categoryIndexFile, 'utf8')
if (categoryIndexFile.endsWith('github/getting-started-with-github/index.md')) {
categoryIndexContent = stripHtmlComments(categoryIndexContent.replace(/\n<!--/g, '<!--'))
}
// find array of TOC link strings
const rawItems = categoryIndexContent.match(linksArray)
if (!rawItems || !rawItems[0].includes('topic_link_in_list')) return
const pageToc = {}
let currentTopic = ''
// Create an object of topics and articles
rawItems.forEach((tocItem) => {
const relativePath = tocItem.match(relativeRefRegex).pop().replace('/', '')
if (tocItem.includes('topic_link_in_list')) {
currentTopic = relativePath
pageToc[relativePath] = []
} else {
const tmpArray = pageToc[currentTopic]
tmpArray.push(relativePath)
pageToc[currentTopic] = tmpArray
}
})
for (const topic in pageToc) {
const oldTopicDirectory = path.dirname(categoryIndexFile)
const newTopicDirectory = path.join(oldTopicDirectory, topic)
const oldTopicFile = path.join(oldTopicDirectory, `${topic}.md`)
// Some translated category TOCs may be outdated and contain incorrect links
if (!fs.existsSync(oldTopicFile)) continue
if (!fs.existsSync(newTopicDirectory)) fs.mkdirSync(newTopicDirectory)
const { data, content } = frontmatter(fs.readFileSync(oldTopicFile, 'utf8'))
delete data.mapTopic
let topicContent = content
const articles = pageToc[topic]
articles.forEach((article) => {
// Update the new map topic index file content
topicContent = topicContent + `{% link_with_intro /${article} %}\n`
// Update the category index file content
categoryIndexContent = categoryIndexContent.replace(
`{% link_in_list /${article}`,
`{% link_in_list /${topic}/${article}`
)
// Early return if the article doesn't exist (some translated category TOCs may be outdated and contain incorrect links)
if (!fs.existsSync(`${oldTopicDirectory}/${article}.md`)) return
// Move the file under the new map topic directory
const newArticlePath = `${newTopicDirectory}/${article}.md`
fs.renameSync(`${oldTopicDirectory}/${article}.md`, newArticlePath)
// Read the article file so we can add a redirect from its old path
const articleContents = frontmatter(fs.readFileSync(newArticlePath, 'utf8'))
if (!articleContents.data.redirect_from) articleContents.data.redirect_from = []
addRedirectToFrontmatter(
articleContents.data.redirect_from,
`${oldTopicDirectory.replace(/^.*?\/content\//, '/')}/${article}`
)
// Write the article with updated frontmatter
fs.writeFileSync(
newArticlePath,
frontmatter.stringify(articleContents.content.trim(), articleContents.data, {
lineWidth: 10000,
})
)
})
// Write the map topic index file
fs.writeFileSync(
`${newTopicDirectory}/index.md`,
frontmatter.stringify(topicContent.trim(), data, { lineWidth: 10000 })
)
// Write the category index file
fs.writeFileSync(categoryIndexFile, categoryIndexContent)
// Delete the old map topic
fs.unlinkSync(oldTopicFile)
}
})

View File

@@ -1,37 +0,0 @@
#!/usr/bin/env node
import { fileURLToPath } from 'url'
import path from 'path'
import walk from 'walk-sync'
import replace from 'replace'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const FINDER = /{{\s?site\.data\.([a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]+)+)\s*}}/g
const REPLACER = '{% data $1 %}'
async function rewriteFiles(dir) {
const files = walk(dir, { includeBasePath: true })
replace({
regex: FINDER,
replacement: REPLACER,
paths: files,
recursive: true,
})
}
async function main() {
const dirs = [
path.join(__dirname, '../../content'),
path.join(__dirname, '../../data'),
path.join(__dirname, '../../translations'),
path.join(__dirname, '../../includes'),
path.join(__dirname, '../../layouts'),
]
for (const dir of dirs) {
await rewriteFiles(dir)
}
}
main()
.catch(console.error)
.finally(() => console.log('Done!'))

View File

@@ -1,112 +0,0 @@
#!/usr/bin/env node
import fs from 'fs'
import path from 'path'
import walk from 'walk-sync'
import frontmatter from '../../lib/read-frontmatter.js'
import getDocumentType from '../../lib/get-document-type.js'
import languages from '../../lib/languages.js'
import ExtendedMarkdown from '../../lib/liquid-tags/extended-markdown.js'
const extendedMarkdownTags = Object.keys(ExtendedMarkdown.tags)
const linkString = /{% [^}]*?link.*? (\/.*?) ?%}/m
const linksArray = new RegExp(linkString.source, 'gm')
// This script turns `{% link /<link> %} style content into children: [ -/<link> ] frontmatter arrays.
//
// It MUST be run after script/content-migrations/remove-map-topics.js.
//
// NOTE: The results won't work with the TOC handling currently in production, so the results must NOT
// be committed until the updated handling is in place.
const walkOpts = {
includeBasePath: true,
directories: false,
}
const fullDirectoryPaths = Object.values(languages).map((langObj) =>
path.join(process.cwd(), langObj.dir, 'content')
)
const indexFiles = fullDirectoryPaths
.map((fullDirectoryPath) => walk(fullDirectoryPath, walkOpts))
.flat()
.filter((file) => file.endsWith('index.md'))
const englishHomepageData = {
children: '',
externalProducts: '',
}
indexFiles.forEach((indexFile) => {
const relativePath = indexFile.replace(/^.+\/content\//, '')
const documentType = getDocumentType(relativePath)
const { data, content } = frontmatter(fs.readFileSync(indexFile, 'utf8'))
// Save the English homepage frontmatter props...
if (documentType === 'homepage' && !indexFile.includes('/translations/')) {
englishHomepageData.children = data.children
englishHomepageData.externalProducts = data.externalProducts
}
// ...and reuse them in the translated homepages, in case the translated files are out of date
if (documentType === 'homepage' && indexFile.includes('/translations/')) {
data.children = englishHomepageData.children
data.externalProducts = englishHomepageData.externalProducts
}
const linkItems = content.match(linksArray)
if (!linkItems) return
// Turn the `{% link /<link> %}` list into an array of /<link> items
if (documentType === 'product' || documentType === 'mapTopic') {
data.children = getLinks(linkItems)
}
if (documentType === 'category') {
const childMapTopics = linkItems.filter((item) => item.includes('topic_'))
data.children = childMapTopics.length ? getLinks(childMapTopics) : getLinks(linkItems)
}
// Fix this one weird file
if (relativePath === 'discussions/guides/index.md') {
data.children = [
'/best-practices-for-community-conversations-on-github',
'/finding-your-discussions',
'/granting-higher-permissions-to-top-contributors',
]
}
// Remove the Table of Contents section and leave any body text before it.
let newContent = content
.replace(/^#*? Table of contents[\s\S]*/im, '')
.replace('<div hidden>', '')
.replace(linksArray, '')
const linesArray = newContent.split('\n')
const newLinesArray = linesArray
.filter(
(line, index) =>
/\S/.test(line) ||
extendedMarkdownTags.find(
(tag) =>
(linesArray[index - 1] && linesArray[index - 1].includes(tag)) ||
(linesArray[index + 1] && linesArray[index + 1].includes(tag))
)
)
.filter((line) => !/^<!--\s+?-->$/m.test(line))
newContent = newLinesArray.join('\n')
// Index files should no longer have body content, so we write an empty string
fs.writeFileSync(indexFile, frontmatter.stringify(newContent, data, { lineWidth: 10000 }))
})
function getLinks(linkItemArray) {
// do a oneoff replacement while mapping
return linkItemArray.map((item) =>
item.match(linkString)[1].replace('/discussions-guides', '/guides')
)
}