Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const { encodeURL, full_url_for } = require('hexo-util');
env.addFilter('uriencode', str => {
return encodeURI(str);
});
env.addFilter('noControlChars', str => {
return str.replace(/[\x00-\x1F\x7F]/g, ''); // eslint-disable-line no-control-regex
});
const atomTmplSrc = join(__dirname, '../atom.xml');
const atomTmpl = nunjucks.compile(readFileSync(atomTmplSrc, 'utf8'), env);
const rss2TmplSrc = join(__dirname, '../rss2.xml');
const rss2Tmpl = nunjucks.compile(readFileSync(rss2TmplSrc, 'utf8'), env);
const customTmplSrc = join(__dirname, 'custom.xml');
const customTmlp = nunjucks.compile(readFileSync(customTmplSrc, 'utf8'), env);
const urlConfig = {
url: 'http://localhost/',
root: '/'
};
describe('Feed generator', () => {
const hexo = new Hexo(__dirname, {
silent: true
});
const Post = hexo.model('Post');
const generator = require('../lib/generator').bind(hexo);
require('../node_modules/hexo/lib/plugins/helper')(hexo);
let posts = {};
const { readFileSync } = require('fs');
const cheerio = require('cheerio');
const { encodeURL, full_url_for } = require('hexo-util');
env.addFilter('uriencode', str => {
return encodeURI(str);
});
env.addFilter('noControlChars', str => {
return str.replace(/[\x00-\x1F\x7F]/g, ''); // eslint-disable-line no-control-regex
});
const atomTmplSrc = join(__dirname, '../atom.xml');
const atomTmpl = nunjucks.compile(readFileSync(atomTmplSrc, 'utf8'), env);
const rss2TmplSrc = join(__dirname, '../rss2.xml');
const rss2Tmpl = nunjucks.compile(readFileSync(rss2TmplSrc, 'utf8'), env);
const customTmplSrc = join(__dirname, 'custom.xml');
const customTmlp = nunjucks.compile(readFileSync(customTmplSrc, 'utf8'), env);
const urlConfig = {
url: 'http://localhost/',
root: '/'
};
describe('Feed generator', () => {
const hexo = new Hexo(__dirname, {
silent: true
});
const Post = hexo.model('Post');
const generator = require('../lib/generator').bind(hexo);
require('../node_modules/hexo/lib/plugins/helper')(hexo);
fs.mkdirSync(this.intermediary_folder, {recursive: true});
}
this.output_folder = this.parent.output_folder + this.path_slug;
if (!fs.existsSync(__dirname + '/' + this.output_folder)) {
fs.mkdirSync(this.output_folder, {recursive: true});
}
console.log('template loaded:');
console.log(this);
// read the template itself
this.template_contents = fs.readFileSync(this.template_file, 'utf8');
// prepare for templatizing
this.compiled_file_name = nunjucks.compile(this.file_name);
this.compiled_template = nunjucks.compile(this.template_contents);
}
if (!fs.existsSync(__dirname + '/' + this.intermediary_folder)) {
fs.mkdirSync(this.intermediary_folder, {recursive: true});
}
this.output_folder = this.parent.output_folder + this.path_slug;
if (!fs.existsSync(__dirname + '/' + this.output_folder)) {
fs.mkdirSync(this.output_folder, {recursive: true});
}
console.log('template loaded:');
console.log(this);
// read the template itself
this.template_contents = fs.readFileSync(this.template_file, 'utf8');
// prepare for templatizing
this.compiled_file_name = nunjucks.compile(this.file_name);
this.compiled_template = nunjucks.compile(this.template_contents);
}
async generateTagsPages(postsMetadata) {
const tagTemplateNJ = nunjucks.compile(this.theme.getFileContents('index.html'), this.nunjucksEnv);
const config = this.config;
await Promise.all([].concat(...Object.entries(postsMetadata).map(([lang, langPosts]) => {
const postsByTag = {};
langPosts.forEach((post) => {
post.categories.forEach((category) => {
// TODO replace with kebabCase?
const tag = category.toLowerCase().trim().split(' ').join('-');
postsByTag[tag] = postsByTag[tag] || [];
postsByTag[tag].push(post);
});
});
return Object.entries(postsByTag).map(async ([tag, tagPosts]) => {
const tagContent = tagTemplateNJ.render({
posts: tagPosts,
compile: (src, options) => {
const template = Nunjucks.compile(src, options.environment)
return function (context) {
return template.render(context)
}
},
prepare: (options, next) => {
'use strict';
var nunjucks = require('nunjucks');
var env = new nunjucks.Environment();
var pathFn = require('path');
var fs = require('fs');
env.addFilter('uriencode', function(str) {
return encodeURI(str);
});
env.addFilter('noControlChars', function(str) {
return str && str.replace(/[\x00-\x1F\x7F]/g, '');
});
var searchTmplSrc = pathFn.join(__dirname, '../templates/search.xml');
var searchTmpl = nunjucks.compile(fs.readFileSync(searchTmplSrc, 'utf8'), env);
module.exports = function(locals){
var config = this.config;
var searchConfig = config.search;
var template = searchTmpl;
var searchfield = searchConfig.field;
var content = searchConfig.content;
if (content == undefined) content=true;
var posts, pages;
if(searchfield.trim() != ''){
searchfield = searchfield.trim();
if(searchfield == 'post'){
posts = locals.posts.sort('-date');
}else if(searchfield == 'page'){
{# Site icon #}
{% if icon %}
{% endif %}
{# Supports adding arbitrary markup to start #}
{{ bodyStart | safe }}
{# React page content. #}
<div class="react--loading" id="react">`
.replace(/\t/g, ''))
const TEMPLATE_AFTER_CONTENT = nunjucks.compile
(`</div>
{% if serverSideRender %}
{#
Server-Side Rendering "renderContent" flag.
It is used to determine whether to call
"ReactDOM.hydrate()" or "ReactDOM.render()".
#}
async compile(str, inputPath) {
let tmpl = NunjucksLib.compile(str, this.njkEnv);
return async function(data) {
return new Promise(function(resolve, reject) {
tmpl.render(data, function(err, res) {
if (err) {
reject(err);
} else {
resolve(res);
}
});
});
};
}
}
compile: (src, options) => {
const template = Nunjucks.compile(src, options.environment);
return (context) => {
return template.render(context);
};
},
prepare: (options, next) => {