Skip to content

Commit

Permalink
Added scripts and fragments (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
writinwaters authored May 17, 2024
1 parent c3b6905 commit c963ad9
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
Empty file added website/fragments/.gitkeep
Empty file.
52 changes: 52 additions & 0 deletions website/scripts/validation/index.js
Original file line number Diff line number Diff line change
@@ -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)
31 changes: 31 additions & 0 deletions website/scripts/versions/index.js
Original file line number Diff line number Diff line change
@@ -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))

0 comments on commit c963ad9

Please sign in to comment.