Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
await Promise.all(results.map(async (result: any, index: any) => {
const postMatter = matter(result)
const data = (postMatter.data as any)
data.title = formatYamlString(data.title)
if (data && data.date) {
if (typeof data.date === 'string') {
data.date = moment(data.date).format('YYYY-MM-DD HH:mm:ss')
} else {
data.date = moment(data.date).subtract(8, 'hours').format('YYYY-MM-DD HH:mm:ss')
}
}
// If there is a `tag` and it is of string type, it is corrected to array type.
if (data && typeof data.tags === 'string') {
const tagReg = /tags: [^\s[]/i
const newTagString = data.tags.split(' ').toString()
const parse = (src, options) => {
const inlineModules = [];
const { data, content } = matter(src);
const separatedContent = normalizeNewline(content)
/*
* Set aside all inline JSX import and export statements from the MDX file.
* When mdx.sync() compiles MDX into JSX, it will stub any component that doesn't
* have a corresponding import. Therefore, we will re-add all of the imports/exports
* to each slide before compiling the MDX via mdx.sync().
*/
.replace(MOD_REG, (value, group1) => {
if (!group1) {
// group1 is empty, so this is not the import/export case we're looking for
return value;
} else {
// found an inline export or import statement
inlineModules.push(value);
return '';
get _rawData(): Nuxtent.Page.RawData {
if (isDev || !this.cached.data.fileName) {
const source = readFileSync(this.__meta.filePath).toString()
const fileName = this.__meta.fileName
this.cached.data.fileName = fileName
if (fileName.search(/\.(md|html)$/) !== -1) {
// { data: attributes, content: body } = matter(source)
const result = matter(source, {
excerpt: !!this.config.excerpt,
})
this.cached.data.attributes = result.data
if (!!this.config.excerpt) {
this.cached.data.attributes.excerpt =
fileName.endsWith('md') &&
this.config.markdown.parser &&
result.excerpt
? this.config.markdown.parser.render(result.excerpt)
: result.excerpt
}
this.cached.data.body.content = result.content
} else if (fileName.search(/\.(yaml|yml)$/) !== -1) {
this.cached.data.body.content = yaml.load(source)
} else if (fileName.endsWith('.json')) {
this.cached.data.body.content = JSON.parse(source)
context: GetStaticPropsContext<{ path: string[] }>
): Promise> {
const { locale } = context;
const route = context?.params.path || ["index"];
let result: { source: string; fallback: boolean };
const path = route.join("/");
try {
result = await readLocaleDocs(path, locale);
} catch (e) {
return {
props: { error: `File ${path} (${locale}) not found: ${e.message}` },
};
}
const { content, data } = matter(result.source);
// TODO: plugins for admonitions and frontmatter etc
// also, pawn syntax highlighting
const mdxSource = await renderToString(content, {
components,
remarkPlugins: [admonitions],
});
return {
props: {
source: mdxSource,
data,
fallback: result.fallback,
},
};
}
export = function parseFrontmatter (content: string) {
return matter(content, {
// eslint-disable-next-line @typescript-eslint/camelcase
excerpt_separator: '',
engines: {
toml: toml.parse.bind(toml)
}
})
}
axios.get(matter.extends.toString()).then(res => {
md.isExtending = true;
md.extendMatter = matter;
const addition = '\n' + grayMatter(store.state.current.raw_content).content;
store.commit('SET_CURRENT_RAW_CONTENT', res.data);
store.commit('SET_CURRENT_CONTENT', md.render(res.data) + md.render(addition));
});
}
export default ({
components,
theme = {},
code,
className,
frontmatter,
...props
}) => {
const fullScope = Object.assign({}, components, {
...frontmatter,
ThemeProvider,
theme
})
const lang = (className[0] || '').split(/-\./)[1] || 'jsx'
const parsedCode = matter(code)
return (
transformCode(newCode, theme, lang)}
{...props}
>
{parsedCode.data.liveEditor ? : null}
)
}
constructor (props) {
super()
const {
code,
theme,
components,
scope
} = props
const { content, data = {} } = matter(code)
const defaultScope = {
ThemeProvider,
XRay,
props,
theme
}
const fullScope = Object.assign(defaultScope, components, scope)
this.state = {
fullScope,
rawCode: content,
options: data,
xray: false,
viewport: data.viewport
`The folder ${section} is not configured in nuxtent and therefore ignored`
)
return
}
const [, fileName = ''] =
this.resourcePath.match(/[/\\]content([/\\\w\-_]*)(\.comp\.md$)?|$/) || []
if (!fileName) {
this.emitError(new Error('The resource is not a markdown file'))
}
if (!dirOpts.markdown.parser) {
return this.emitError(new Error('Could not found markdown parser'))
}
const frontmatter = matter(source)
const { transformedSource, components } = transformMdComponents(
frontmatter.content,
componentsDir,
extensions
)
/**
* import components from the array on the frontmatter $components
*/
if (
frontmatter.data.$components &&
Array.isArray(frontmatter.data.$components)
) {
for (const name of frontmatter.data.$components) {
const usedComponent = _.camelCase(name)