mirror of
https://github.com/Fechin/reference.git
synced 2026-11-21 21:44:45 +03:00
16 lines
453 B
JavaScript
16 lines
453 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);
|
|
});
|