website: fixes and tweaks for plugin docs (#10812)

* website: sort nested plugin docs files

* website: allow ignored .md files in plugin docs folders

* website: allow plugin docs/README.md only as extra file

* website: fix issue with latest link for plugin docs.zip
This commit is contained in:
Zachary Shilton 2021-03-23 16:06:50 -04:00 committed by GitHub
parent 5e17dbeff2
commit 89931d0f2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 9 deletions

View File

@ -13,7 +13,10 @@ const parseDocsZip = require('./parse-docs-zip')
// docs files were missing or invalid, with a path to resolution
async function fetchDocsFiles({ repo, tag }) {
// If there's a docs.zip asset, we'll prefer that
const docsZipUrl = `https://github.com/${repo}/releases/download/${tag}/docs.zip`
const docsZipUrl =
tag === 'latest'
? `https://github.com/${repo}/releases/latest/download/docs.zip`
: `https://github.com/${repo}/releases/download/${tag}/docs.zip`
const docsZipResponse = await fetch(docsZipUrl, { method: 'GET' })
const hasDocsZip = docsZipResponse.status === 200
// Note: early return!

View File

@ -95,16 +95,19 @@ async function mergeRemotePlugins(remotePluginsFile, navData) {
// console.log(JSON.stringify(routesWithPlugins, null, 2))
// Also, sort the child routes so the order is alphabetical
routesWithPlugins.sort((a, b) => {
// ensure casing does not affect ordering
const aTitle = a.title.toLowerCase()
const bTitle = b.title.toLowerCase()
// (exception: "Overview" comes first)
if (a.title == 'Overview') return -1
if (b.title === 'Overview') return 1
if (aTitle === 'overview') return -1
if (bTitle === 'overview') return 1
// (exception: "Community-Supported" comes last)
if (a.title == 'Community-Supported') return 1
if (b.title === 'Community-Supported') return -1
if (aTitle === 'community-supported') return 1
if (bTitle === 'community-supported') return -1
// (exception: "Custom" comes second-last)
if (a.title == 'Custom') return 1
if (b.title === 'Custom') return -1
return a.title < b.title ? -1 : a.title > b.title ? 1 : 0
if (aTitle === 'custom') return 1
if (bTitle === 'custom') return -1
return aTitle < bTitle ? -1 : aTitle > bTitle ? 1 : 0
})
// return n
return { ...n, routes: routesWithPlugins }
@ -159,6 +162,16 @@ async function resolvePluginEntryDocs(pluginConfigEntry) {
}
})
//
navNodes.sort((a, b) => {
// ensure casing does not affect ordering
const aTitle = a.title.toLowerCase()
const bTitle = b.title.toLowerCase()
// (exception: "Overview" comes first)
if (aTitle === 'overview') return -1
if (bTitle === 'overview') return 1
return aTitle < bTitle ? -1 : aTitle > bTitle ? 1 : 0
})
//
const navNodesByComponent = navNodes.reduce((acc, navLeaf) => {
const componentType = navLeaf.remoteFile.filePath.split('/')[1]
if (!acc[componentType]) acc[componentType] = []

View File

@ -13,15 +13,22 @@ const COMPONENT_TYPES = [
// with at least one .mdx file within it.
function validatePluginDocsFiles(filePaths) {
function isValidPath(filePath) {
// Allow the docs root folder
const isDocsRoot = filePath === 'docs/'
// Allow component folders
const isComponentRoot = COMPONENT_TYPES.reduce((acc, type) => {
return acc || filePath === `docs/${type}/`
}, false)
// Allow .mdx files in component folders
const isComponentMdx = COMPONENT_TYPES.reduce((acc, type) => {
const mdxPathRegex = new RegExp(`^docs/${type}/(.*).mdx$`)
return acc || mdxPathRegex.test(filePath)
}, false)
const isValidPath = isDocsRoot || isComponentRoot || isComponentMdx
// Allow docs/README.md files
const isDocsReadme = filePath == 'docs/README.md'
// Combine all allowed types
const isValidPath =
isDocsRoot || isComponentRoot || isComponentMdx || isDocsReadme
return isValidPath
}
const invalidPaths = filePaths.filter((f) => !isValidPath(f))