@@ -36,7 +36,7 @@ runs:
|
||||
- name: Run script
|
||||
if: ${{ inputs.restore-only == '' }}
|
||||
shell: bash
|
||||
run: npm run precompute-pageinfo
|
||||
run: npm run precompute-pageinfo -- --max-versions 2
|
||||
|
||||
- name: Cache .remotejson-cache (save)
|
||||
if: ${{ inputs.restore-only == '' }}
|
||||
|
||||
2
.github/workflows/codeowners-legal.yml
vendored
2
.github/workflows/codeowners-legal.yml
vendored
@@ -28,7 +28,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Get files changed
|
||||
uses: dorny/paths-filter@4512585405083f25c027a35db413c2b3b9006d50
|
||||
uses: dorny/paths-filter@0bc4621a3135347011ad047f9ecf449bf72ce2bd
|
||||
id: filter
|
||||
with:
|
||||
# Base branch used to get changed files
|
||||
|
||||
@@ -91,6 +91,14 @@ jobs:
|
||||
# Needed for gh
|
||||
GH_TOKEN: ${{ secrets.DOCS_BOT_PAT_READPUBLICKEY }}
|
||||
run: |
|
||||
# If nothing to commit, exit now. It's fine. No orphans.
|
||||
changes=$(git diff --name-only | wc -l)
|
||||
untracked=$(git status --untracked-files --short | wc -l)
|
||||
if [[ $changes -eq 0 ]] && [[ $untracked -eq 0 ]]; then
|
||||
echo "There are no changes to commit after running src/rest/scripts/update-files.js. Exiting..."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
git status
|
||||
current_timestamp=$(date '+%Y-%m-%d-%H%M%S')
|
||||
branch_name="delete-orphan-files-$current_timestamp"
|
||||
|
||||
@@ -29,7 +29,7 @@ jobs:
|
||||
uses: ./.github/actions/node-npm-setup
|
||||
|
||||
- name: Get files changed
|
||||
uses: dorny/paths-filter@4512585405083f25c027a35db413c2b3b9006d50
|
||||
uses: dorny/paths-filter@0bc4621a3135347011ad047f9ecf449bf72ce2bd
|
||||
id: filter
|
||||
with:
|
||||
# Base branch used to get changed files
|
||||
|
||||
@@ -87,10 +87,12 @@ function createAnnotatedNode(node) {
|
||||
|
||||
// Group groups into rows
|
||||
const rows = chunk(groups, 2)
|
||||
for (const [, note] of rows) {
|
||||
if (note === undefined) {
|
||||
|
||||
// Check the rows are formatted correctly
|
||||
for (const [note, code] of rows) {
|
||||
if (note === undefined || code === undefined) {
|
||||
throw new Error(
|
||||
"Unbalanced code meaning there's a comment (note) that is not followed by any code.",
|
||||
"Each annotation must have a note and a code block. If you're trying to create a blank annotation, you can use a single line comment with a space after it.",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,21 +40,24 @@ program
|
||||
.description('Generates a JSON file with precompute pageinfo data by pathname')
|
||||
.addOption(
|
||||
new Option('-l, --language <LANGUAGE...>', 'Which languages to focus on')
|
||||
.choices(languageKeys)
|
||||
.choices(languageKeys.concat('all'))
|
||||
.default(['en']),
|
||||
)
|
||||
.option('-o, --output-file <path>', 'path to output file', CACHE_FILE_PATH)
|
||||
.option('--max-versions <number>', 'max. number of permalink versions per page')
|
||||
.parse(process.argv)
|
||||
|
||||
type Options = {
|
||||
outputFile: string
|
||||
languages: string[]
|
||||
maxVersions: number
|
||||
}
|
||||
const opts = program.opts()
|
||||
|
||||
main({
|
||||
outputFile: opts.outputFile,
|
||||
languages: opts.language,
|
||||
maxVersions: isNaN(opts.maxVersions) ? 1 : Number(opts.maxVersions),
|
||||
})
|
||||
|
||||
const CI = Boolean(JSON.parse(process.env.CI || 'false'))
|
||||
@@ -66,10 +69,16 @@ type PageInfo = {
|
||||
}
|
||||
|
||||
async function main(options: Options) {
|
||||
const { outputFile, languages } = options
|
||||
const { outputFile, languages, maxVersions } = options
|
||||
if (outputFile !== CACHE_FILE_PATH) {
|
||||
console.warn(chalk.yellow(`Writing to ${outputFile} instead of ${CACHE_FILE_PATH}`))
|
||||
}
|
||||
if (languages.includes('all')) {
|
||||
// This sets it to [], which when sent into loadUnversionedTree means
|
||||
// it does all languages that it can find.
|
||||
languages.length = 0
|
||||
}
|
||||
|
||||
const unversionedTree = await loadUnversionedTree(languages)
|
||||
const pageList = await loadPages(unversionedTree, languages)
|
||||
|
||||
@@ -79,15 +88,25 @@ async function main(options: Options) {
|
||||
[pathname: string]: PageInfo
|
||||
} = {}
|
||||
for (const page of pageList) {
|
||||
const pathname = page.permalinks[0].href
|
||||
try {
|
||||
const computed = await getPageInfo(page, pathname)
|
||||
if (computed) {
|
||||
pageinfos[pathname] = computed
|
||||
let countVersions = 0
|
||||
for (const permalink of page.permalinks) {
|
||||
const pathname = permalink.href
|
||||
try {
|
||||
const computed = await getPageInfo(page, pathname)
|
||||
if (computed) {
|
||||
pageinfos[pathname] = computed
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Error computing pageinfo for ${page.fullPath} (${pathname})`)
|
||||
throw error
|
||||
}
|
||||
// By default, we only compute the first permalink href.
|
||||
// But you can do more if you want.
|
||||
if (++countVersions >= maxVersions) {
|
||||
// This means we're content with only doing the first permalink href.
|
||||
// That's 99% the free-pro-team permalink pathname.
|
||||
break
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Error computing pageinfo for ${page.fullPath} (${pathname})`)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
console.timeEnd(label)
|
||||
|
||||
Reference in New Issue
Block a user