Support for uncached data loading
So you don't have to restart the server, you can add "cache_data": false option to config.json to not cache data. Documented in CONFIG.md I added a require_module function that either does or does not cache the data based on this configuration option. Signed-off-by: deadvey <deadvey@deadvey.com>
This commit is contained in:
@@ -4,6 +4,19 @@ const config = require("../config.json")
|
||||
const fs = require('fs')
|
||||
const locale = require(`../locales/${config.locale}.json`)
|
||||
|
||||
// This function requires a module without caching it
|
||||
// So the server doesn't need to be restarted, though this can slow it down a bit.
|
||||
// https://stackoverflow.com/a/16060619
|
||||
export function require_module(module) {
|
||||
if (config.cache_data == false) {
|
||||
delete require.cache[require.resolve(module)];
|
||||
return require(module);
|
||||
}
|
||||
else {
|
||||
return require(module);
|
||||
}
|
||||
}
|
||||
|
||||
// The configuration defines a date format using the date-fns (a datetime library) syntax
|
||||
// eg "yyyy-MM-dd"
|
||||
// this converts unix time (an integer) into a string that is formatted according to config.js
|
||||
@@ -86,6 +99,7 @@ export function escape_input(input) {
|
||||
}
|
||||
|
||||
// Render comment content by replacing the >> int with a url link to that comment
|
||||
// Syntax: ">> postID-commentID"
|
||||
export function render_comment(comment_content) {
|
||||
return comment_content
|
||||
.replaceAll(/>> ([0-9]*)-([0-9]*)/g, "<a href='/comment/$1-$2'>>> $1-$2</a>")
|
||||
@@ -95,9 +109,11 @@ export function render_comment(comment_content) {
|
||||
.replaceAll("\n", "<br/>")
|
||||
|
||||
};
|
||||
|
||||
// Renders a string into markdown using markdown-it library
|
||||
export function render_md(content) {
|
||||
const markdownit = require("markdown-it")
|
||||
const md = markdownit({
|
||||
const md = markdownit({ // this is just defining some options for markdown-it, should I add this to config.json?
|
||||
html: false,
|
||||
xhtmlOut: false,
|
||||
breaks: true,
|
||||
|
Reference in New Issue
Block a user