开发者文档

This commit is contained in:
undefined committed 2020-05-06 12:40:24 +08:00
1 parent 3e9b074e77
commit e7ce8c1f02
42 files changed
+349 -297

No files matched your search

+3 -3
View File
@@ -15,7 +15,7 @@ async function getInstalled() {
const files = fs.readdirSync(root('.build/module'));
const installed = [];
for (const file of files) {
if (file.endsWith('.hydro-module')) {
if (file.endsWith('.hydro')) {
const f = fs.readFileSync(root(`.build/module/${file}`));
const s = fs.statSync(root(`.build/module/${file}`));
installed.push({
@@ -29,11 +29,11 @@ async function getInstalled() {
}
async function del(id) {
fs.unlinkSync(root(`.build/module/${id}.hydro-module`));
fs.unlinkSync(root(`.build/module/${id}.hydro`));
}
async function install(id, url) {
await download(url, root(`module/${id}.hydro-module`));
await download(url, root(`module/${id}.hydro`));
}
module.exports = { getInstalled, del, install };
+1 -1
View File
@@ -1,4 +1,4 @@
const locales = require('../../.build/locales.json');
const locales = {};
String.prototype.format = function formatStr(...args) {
let result = this;
+6 -2
View File
@@ -7,7 +7,7 @@ const loadLanguages = require('prismjs/components/');
loadLanguages(['js', 'javascript', 'go', 'c', 'pascal', 'hs', 'java', 'cs', 'cpp', 'py', 'ruby']);
class Markdown extends MarkdownIt {
constructor() {
constructor(safe) {
super({
linkify: true,
highlight(str, lang) {
@@ -18,9 +18,13 @@ class Markdown extends MarkdownIt {
}
return '';
},
html: !safe,
});
this.linkify.tlds('.py', false);
this.use(katex);
}
}
module.exports = new Markdown();
module.exports = {
unsafe: new Markdown(false),
safe: new Markdown(true),
};
+4 -1
View File
@@ -19,7 +19,10 @@ class Nunjucks extends nunjucks.Environment {
super(new Loader(), { autoescape: true, trimBlocks: true });
this.addFilter('json', (self) => JSON.stringify(self), false);
this.addFilter('assign', (self, data) => Object.assign(self, data));
this.addFilter('markdown', (self) => markdown.render(self));
this.addFilter('markdown', (self, safe = true) => {
if (safe) return markdown.safe.render(self);
return markdown.unsafe.render(self);
});
this.addFilter('base64_encode', (s) => Buffer.from(s).toString('base64'));
}
}
+1 -1
View File
@@ -15,7 +15,7 @@ const active = [];
async function preload() {
const files = fs.readdirSync(root('.build/module'));
for (const file of files) {
if (file.endsWith('.hydro-module')) {
if (file.endsWith('.hydro')) {
const f = fs.readFileSync(root(`.build/module/${file}`));
active.push({ ...yaml.safeLoad(zlib.gunzipSync(f)), id: file.split('.')[0] });
}