mirror of
https://github.com/Fechin/reference.git
synced 2026-11-22 14:01:45 +03:00
Formats all the general js files. Separate in case these should be treated differently for any reason. This commit includes all javascript and HTML files.
16 lines
434 B
JavaScript
16 lines
434 B
JavaScript
const path = require("path");
|
|
const fs = require("hexo-fs");
|
|
|
|
const outputFile = path.resolve("./", "source/ga_analytics_tops.json");
|
|
const cache = new Map();
|
|
|
|
hexo.extend.helper.register("topPosts", function (maximum = 4) {
|
|
let posts = cache.get(outputFile);
|
|
if (!posts) {
|
|
let content = fs.readFileSync(outputFile);
|
|
posts = JSON.parse(content);
|
|
cache.set(outputFile, posts);
|
|
}
|
|
return posts.slice(0, maximum);
|
|
});
|