Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function partial(name, context) {
if (!Array.isArray(assemble.partials)) {
assemble.partials = [assemble.partials];
}
var filepath = _.first(_.filter(assemble.partials, function (fp) {
return path.basename(fp, path.extname(fp)) === name;
}));
// Process context, using YAML front-matter,
// grunt config and Assemble options.data
var pageObj = matter.read(filepath) || {};
var metadata = pageObj.context || {};
// `context` = the given context (second parameter)
// `metadata` = YAML front matter of the partial
// `opts.data[name]` = JSON/YAML data file defined in Assemble options.data
// with a basename matching the name of the partial, e.g
// {{include 'foo'}} => foo.json
// `this` = Typically either YAML front matter of the "inheriting" page,
// layout, block expression, or "parent" helper wrapping this helper
// `opts` = Custom properties defined in Assemble options
// `grunt.config.data` = Data from grunt.config.data
// (e.g. pkg: grunt.file.readJSON('package.json'))
var omit = function (target) {
return _.omit(target, 'pages', 'pagination');
};
Document.prototype.load = function () {
// Get config and content
var input = matter.read(this.file(), {
delims: [''],
lang: 'json',
});
this._config = (input.data || {});
this._content = input.content;
// Load config.json if no front matter is available
if (Object.keys(this._config).length === 0) {
var configFile = path.join(this.path(), 'config.json');
if (fs.existsSync(configFile)) {
this._config = require(configFile);
}
}
};
readInputFile(filePath) {
const ext = path.extname(filePath);
const meta = matter.read(filePath, this.languageConfig);
// Check if is a draft
if (meta.data.draft) return;
const tags = meta.data.tags || [];
let content;
// Content
if (ext === ".md") content = removeMd(meta.content);
else content = striptags(meta.content);
// Uri
let uri = `/${filePath.substring(0, filePath.lastIndexOf("."))}`.replace(`${this.baseDir}/`, "");
if (meta.data.slug) uri = path.dirname(uri) + meta.data.slug;
it('yaml file starts and ends with --- has content', function() {
var page = matter.read('./test/fixtures/yfm/yfm.hbs');
simpleExpected.data.should.eql(page.data);
});
function eachFile (context, file) {
var f = matter.read(file)
var build = path.join(cwd, context.options.build)
var prettyUrl = getPrettyUrl(context, f)
var dest = getDest(file, context.options, prettyUrl)
var meta = {
content: f.content,
file: file,
dest: dest,
url: getUrl(dest, build),
root: path.relative(dest, build),
isMarkdown: isMarkdown(file),
prettyUrl: prettyUrl
}
return assign({}, context.extraOptions, f.data, meta)
}
HugoLunr.prototype.readFile = function(filePath){
var self = this;
var ext = path.extname(filePath);
var meta = matter.read(filePath, {delims: '+++', lang:'toml'});
if (meta.data.draft === true){
return;
}
if (ext == '.md'){
var plainText = removeMd(meta.content);
} else {
var plainText = striptags(meta.content);
}
var uri = '/' + filePath.substring(0,filePath.lastIndexOf('.'));
uri = uri.replace(self.baseDir +'/', '');
if (meta.data.slug != undefined){
uri = path.dirname(uri) + meta.data.slug;
}
function getDocId(docsPath, file) {
const dirname = path.dirname(path.relative(docsPath, file));
const fm = matter.read(file);
const id = fm.data.id || path.parse(file).name;
return path.join(dirname, id);
}
var src = files.map(function (filepath) {
i += 1;
var content = matter.read(filepath).content || '';
var metadata = matter.read(filepath).context || {};
/**
* Process context from last to first, with #1 winning over other contexts.
* 1. `context` : The given context (second parameter)
* 2. `metadata` : YAML front matter of the partial
* 3. `opts.data[name]` : JSON/YAML data file defined in Assemble options.data
* with a basename matching the name of the partial, e.g
* {{include 'foo'}} => foo.json
* 4. `this` : Typically either YAML front matter of the "inheriting" page,
* layout, block expression, or "parent" helper wrapping this helper
* 5. `opts` : Custom properties defined in Assemble options
* 6. `grunt.config.data`: Data from grunt.config.data
* (e.g. pkg: grunt.file.readJSON('package.json'))
*/
var basename = file.basename(filepath);
templates.forEach(function (page) {
var ext = path.extname(page);
var pageObj = matter.read(page);
i18n = _.extend({}, i18n, {languages: languages});
var context = _.extend({}, data, {language: language, i18n: i18n}, pageObj.context);
var filename = defaultLanguage !== language ? page.replace(ext, "-" + language + ext) : page;
pages[filename] = {
filename: filename,
content: pageObj.content,
data: context
};
});
});
var getMatter = function (file) {
return matter.read(file, {
parser: require('js-yaml').safeLoad
});
};