diff --git a/website/fragments/.gitkeep b/website/fragments/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/website/scripts/validation/index.js b/website/scripts/validation/index.js new file mode 100644 index 0000000..1cebce8 --- /dev/null +++ b/website/scripts/validation/index.js @@ -0,0 +1,52 @@ +const fragmentPlugin = require('../../plugins/remark-plugins/fragments'); +const variablePlugin = require('../../plugins/remark-plugins/variables'); +const variables = require('../..//variables'); +const docutils = require('../flaturl/doc'); + +const myArgs = process.argv.slice(2); +let baseurl = './.flatdocs' +if (myArgs.length >= 1) { + baseurl = myArgs[0] +} + +const mdxLoader = require('@docusaurus/mdx-loader').default; +const { + reportMessage, +} = require('@docusaurus/utils') + +const loadContext = (errors) => { + return { + async: () => { + return () => {} + }, + getOptions: () => ({ + remarkPlugins: [ + [variablePlugin, { data: variables, fail: false, onError: (err, line) => {errors.push([err, line])} }], + [fragmentPlugin, { prefix: 'fragments', fail: false, baseUrl: process.cwd() + '/fragments', onError: (err, line) => {errors.push([err, line])} }] + ], + }) + } +} + +async function validateFragmentsAndVariables(contentPath) { + const docs = await docutils.getDocMetadata(contentPath); + let haserrors = false + for (const doc of docs) { + const errors = [] + const context = loadContext(errors) + const mdxLoaderWithContext = mdxLoader.bind(context) + await mdxLoaderWithContext(doc.body) + if (errors.length > 0) { + haserrors = true + reportMessage(`- on source page path = ${doc.source}`, 'error') + for (const item of errors) { + reportMessage(` line:${item[1].line} Column:${item[1].column} ${item[0]}`, 'error') + } + } + } + if (haserrors) { + process.exit(1) + } +} + +validateFragmentsAndVariables(baseurl) diff --git a/website/scripts/versions/index.js b/website/scripts/versions/index.js new file mode 100644 index 0000000..9702f16 --- /dev/null +++ b/website/scripts/versions/index.js @@ -0,0 +1,31 @@ +const shell = require('shelljs') +const fs = require('fs') +const path = require('path') +const semver = require('semver'); +const _ = require('lodash'); + +const writeFile = (file, data) => { + fs.writeFileSync(file, data) +} + +function keepLastNVersion(n) { + const data = shell.exec('cd $RAGFLOW_MAIN && git tag').stdout.trim() + const tags = _.compact(data.split('\n')) + .filter(semver.valid) + .sort(semver.compare) + .reverse(); + const groups = _.groupBy(tags, function(item){ + return semver.major(item) + '.' + semver.minor(item) + }) + let got = 0; + const res = []; + for (const key in groups) { + res.push(groups[key][0]) + got++ + if (got >= n) break + } + return res +} + +const arr = keepLastNVersion(2) +writeFile('./versions.json', JSON.stringify(arr, null, 2)) \ No newline at end of file