* Add custom hover shadows * Support avatars * Add guide-card include * Use it in product-landing * Add gradient styles * Add guides frontmatter * Use guideArticles instead of full objects * Add support for authors * Add support for category header * Just pass the whole page * Use it * guide.url => guide.href * Use `*.githubusercontent.com` * Fix mobile card width * Remove showDescription check * Use featureLinks.guideCards * Forgot an if * Add contextualizers/actions-code-examples * Use code-example-card include * Tweak sizing/shadows * Add a basic filterer * Some visual tweaks * labels => tags * Cleanup some code * Improve spacing on mobile * Add "No results!" blurb * Fix a boog * Tweak spacing * Remove support banner * Improve "No results" state * Just use login instead of name/avatarUrl * Change card spacing * Use circular avatars * Add "Show more" button * Add margin beneath "Guides" * Use smaller font * Assume github.com for code examples * Show two columns at small screen * Make "Show more" a btn * Use the "repo" octicon * Link to contributing guide * Use a YAML file instead of a middleware * Link straight to the file * Fix some wonky markuip * Fix a broken link * Fix the borked test * Allow variables that aren't strings * Fix remaining tests
101 lines
3.4 KiB
JavaScript
101 lines
3.4 KiB
JavaScript
const path = require('path')
|
|
const fs = require('fs')
|
|
const walk = require('walk-sync')
|
|
const matter = require('@github-docs/frontmatter')
|
|
const { zip } = require('lodash')
|
|
const yaml = require('js-yaml')
|
|
|
|
const rootDir = path.join(__dirname, '../..')
|
|
const contentDir = path.join(rootDir, 'content')
|
|
const reusablesDir = path.join(rootDir, 'data/reusables')
|
|
const variablesDir = path.join(rootDir, 'data/variables')
|
|
|
|
/*
|
|
This will match Liquid variable references that contain at least one line break
|
|
between the variable reference and either the `{{` or `}}` tag boundaries.
|
|
|
|
Some examples include:
|
|
|
|
(a)
|
|
{{
|
|
site.data.variables.product.product_name }}
|
|
|
|
(b)
|
|
{{ site.data.variables.product.product_name
|
|
}}
|
|
|
|
(c)
|
|
{{
|
|
site.data.variables.product.product_name
|
|
}}
|
|
|
|
*/
|
|
const liquidRefsWithLinkBreaksRegex = /\{\{[ \t]*\n\s*[^\s}]+\s*\}\}|\{\{\s*[^\s}]+[ \t]*\n\s*\}\}/gm
|
|
|
|
describe('Liquid references', () => {
|
|
describe('must not contain line breaks', () => {
|
|
const mdWalkOptions = {
|
|
globs: ['**/*.md'],
|
|
ignore: ['**/README.md'],
|
|
directories: false,
|
|
includeBasePath: true
|
|
}
|
|
|
|
const contentMarkdownAbsPaths = walk(contentDir, mdWalkOptions).sort()
|
|
const contentMarkdownRelPaths = contentMarkdownAbsPaths.map(p => path.relative(rootDir, p))
|
|
const contentMarkdownTuples = zip(contentMarkdownRelPaths, contentMarkdownAbsPaths)
|
|
|
|
const reusableMarkdownAbsPaths = walk(reusablesDir, mdWalkOptions).sort()
|
|
const reusableMarkdownRelPaths = reusableMarkdownAbsPaths.map(p => path.relative(rootDir, p))
|
|
const reusableMarkdownTuples = zip(reusableMarkdownRelPaths, reusableMarkdownAbsPaths)
|
|
|
|
test.each([...contentMarkdownTuples, ...reusableMarkdownTuples])(
|
|
'in "%s"',
|
|
async (markdownRelPath, markdownAbsPath) => {
|
|
const fileContents = await fs.promises.readFile(markdownAbsPath, 'utf8')
|
|
const { content } = matter(fileContents)
|
|
|
|
const matches = (content.match(liquidRefsWithLinkBreaksRegex) || [])
|
|
const errorMessage = formatRefError('Found unexpected line breaks in Liquid reference:', matches)
|
|
expect(matches.length, errorMessage).toBe(0)
|
|
}
|
|
)
|
|
|
|
// Also test the "data/variables/" YAML files
|
|
const yamlWalkOptions = {
|
|
globs: ['**/*.yml'],
|
|
directories: false,
|
|
includeBasePath: true
|
|
}
|
|
|
|
const variableYamlAbsPaths = walk(variablesDir, yamlWalkOptions).sort()
|
|
const variableYamlRelPaths = variableYamlAbsPaths.map(p => path.relative(rootDir, p))
|
|
const variableYamlTuples = zip(variableYamlRelPaths, variableYamlAbsPaths)
|
|
|
|
test.each(variableYamlTuples)(
|
|
'in "%s"',
|
|
async (yamlRelPath, yamlAbsPath) => {
|
|
const fileContents = await fs.promises.readFile(yamlAbsPath, 'utf8')
|
|
const dictionary = yaml.safeLoad(fileContents, { filename: yamlRelPath })
|
|
|
|
const matches = []
|
|
|
|
for (const [key, content] of Object.entries(dictionary)) {
|
|
if (typeof content !== 'string') continue
|
|
const valMatches = (content.match(liquidRefsWithLinkBreaksRegex) || [])
|
|
if (valMatches.length > 0) {
|
|
matches.push(...valMatches.map((match) => `Key "${key}": ${match}`))
|
|
}
|
|
}
|
|
|
|
const errorMessage = formatRefError('Found unexpected line breaks in Liquid reference:', matches)
|
|
expect(matches.length, errorMessage).toBe(0)
|
|
}
|
|
)
|
|
})
|
|
})
|
|
|
|
function formatRefError (message, breaks) {
|
|
return `${message}\n - ${breaks.join('\n - ')}`
|
|
}
|