[Chore] Update extractor for 30web
This commit is contained in:
@ -16,7 +16,10 @@ module.exports = {
|
||||
distPath: `dist`,
|
||||
testPath: `test`,
|
||||
// General information
|
||||
language: `js`,
|
||||
language:{
|
||||
short: `js`,
|
||||
long: `JavaScript`
|
||||
},
|
||||
// Module information
|
||||
moduleName: `_30s`,
|
||||
rollupInputFile: `imports.temp.js`,
|
||||
|
||||
@ -128,11 +128,11 @@ try {
|
||||
|
||||
output += snippet.attributes.text;
|
||||
|
||||
output += `\`\`\`${config.language}\n${snippet.attributes.codeBlocks.es6}\n\`\`\``;
|
||||
output += `\`\`\`${config.language.short}\n${snippet.attributes.codeBlocks.es6}\n\`\`\``;
|
||||
|
||||
output += misc.collapsible(
|
||||
'Examples',
|
||||
`\`\`\`${config.language}\n${snippet.attributes.codeBlocks.example}\n\`\`\``,
|
||||
`\`\`\`${config.language.short}\n${snippet.attributes.codeBlocks.example}\n\`\`\``,
|
||||
);
|
||||
|
||||
output +=
|
||||
@ -185,11 +185,11 @@ try {
|
||||
|
||||
output += snippet.attributes.text;
|
||||
|
||||
output += `\`\`\`${config.language}\n${snippet.attributes.codeBlocks.es6}\n\`\`\``;
|
||||
output += `\`\`\`${config.language.short}\n${snippet.attributes.codeBlocks.es6}\n\`\`\``;
|
||||
|
||||
output += misc.collapsible(
|
||||
'Examples',
|
||||
`\`\`\`${config.language}\n${snippet.attributes.codeBlocks.example}\n\`\`\``,
|
||||
`\`\`\`${config.language.short}\n${snippet.attributes.codeBlocks.example}\n\`\`\``,
|
||||
);
|
||||
|
||||
output +=
|
||||
|
||||
@ -62,6 +62,7 @@ const completeData = {
|
||||
specification: 'http://jsonapi.org/format/',
|
||||
type: 'snippetArray',
|
||||
scope: SNIPPETS_PATH,
|
||||
language: config.language
|
||||
},
|
||||
};
|
||||
const listingData = {
|
||||
@ -81,6 +82,7 @@ const listingData = {
|
||||
specification: 'http://jsonapi.org/format/',
|
||||
type: 'snippetListingArray',
|
||||
scope: SNIPPETS_PATH,
|
||||
language: config.language
|
||||
},
|
||||
};
|
||||
|
||||
@ -90,6 +92,7 @@ const archiveCompleteData = {
|
||||
specification: 'http://jsonapi.org/format/',
|
||||
type: 'snippetArray',
|
||||
scope: SNIPPETS_ARCHIVE_PATH,
|
||||
language: config.language
|
||||
}
|
||||
};
|
||||
const archiveListingData = {
|
||||
@ -109,6 +112,7 @@ const archiveListingData = {
|
||||
specification: 'http://jsonapi.org/format/',
|
||||
type: 'snippetListingArray',
|
||||
scope: SNIPPETS_ARCHIVE_PATH,
|
||||
language: config.language
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@ -36,11 +36,11 @@ const prepTaggedData = tagDbData =>
|
||||
);
|
||||
const makeExamples = data => {
|
||||
data =
|
||||
data.slice(0, data.lastIndexOf(`\`\`\`${config.language}`)).trim() +
|
||||
data.slice(0, data.lastIndexOf(`\`\`\`${config.language.short}`)).trim() +
|
||||
misc.collapsible(
|
||||
'Examples',
|
||||
data.slice(
|
||||
data.lastIndexOf(`\`\`\`${config.language}`),
|
||||
data.lastIndexOf(`\`\`\`${config.language.short}`),
|
||||
data.lastIndexOf('```'),
|
||||
) + data.slice(data.lastIndexOf('```')),
|
||||
);
|
||||
|
||||
@ -5,6 +5,7 @@ const fs = require('fs-extra'),
|
||||
frontmatter = require('front-matter'),
|
||||
babel = require('@babel/core');
|
||||
const config = require('../../config');
|
||||
const execSync = require('child_process').execSync;
|
||||
|
||||
// Reade all files in a directory
|
||||
const getFilesInDir = (directoryPath, withPath, exclude = null) => {
|
||||
@ -54,7 +55,7 @@ const getCodeBlocks = str => {
|
||||
});
|
||||
}
|
||||
const replacer = new RegExp(
|
||||
`\`\`\`${config.language}([\\s\\S]*?)\`\`\``,
|
||||
`\`\`\`${config.language.short}([\\s\\S]*?)\`\`\``,
|
||||
'g',
|
||||
);
|
||||
results = results.map(v => v.replace(replacer, '$1').trim());
|
||||
@ -102,6 +103,9 @@ const readSnippets = snippetsPath => {
|
||||
},
|
||||
meta: {
|
||||
hash: hashData(data.body),
|
||||
firstSeen: execSync(`git log --diff-filter=A --pretty=format:%at -- snippets/${snippet}`).toString(),
|
||||
lastUpdated: execSync(`git log -n 1 --pretty=format:%at -- snippets/${snippet}`).toString(),
|
||||
updateCount: execSync(`git log --pretty=%H -- snippets/${snippet}`).toString().split('\n').length
|
||||
},
|
||||
};
|
||||
}
|
||||
@ -117,5 +121,5 @@ module.exports = {
|
||||
hashData,
|
||||
getCodeBlocks,
|
||||
getTextualContent,
|
||||
readSnippets,
|
||||
readSnippets
|
||||
};
|
||||
|
||||
@ -78,7 +78,7 @@ const FullCard = ({ snippetData, difficulty, isDarkMode }) => {
|
||||
/>
|
||||
</CopyToClipboard>
|
||||
<pre
|
||||
className={`card-code language-${config.language}`}
|
||||
className={`card-code language-${config.language.short}`}
|
||||
dangerouslySetInnerHTML={{ __html: snippetData.codeHtml }}
|
||||
/>
|
||||
<button
|
||||
|
||||
@ -26,7 +26,7 @@ const getCodeBlocks = str => {
|
||||
});
|
||||
}
|
||||
const replacer = new RegExp(
|
||||
`<pre class="language-${config.language}"><code class="language-${config.language}">([\\s\\S]*?)</code></pre>`,
|
||||
`<pre class="language-${config.language.short}"><code class="language-${config.language.short}">([\\s\\S]*?)</code></pre>`,
|
||||
'g',
|
||||
);
|
||||
results = results.map(v => v.replace(replacer, '$1').trim());
|
||||
@ -85,7 +85,7 @@ const getRawCodeBlocks = str => {
|
||||
});
|
||||
}
|
||||
const replacer = new RegExp(
|
||||
`\`\`\`${config.language}([\\s\\S]*?)\`\`\``,
|
||||
`\`\`\`${config.language.short}([\\s\\S]*?)\`\`\``,
|
||||
'g',
|
||||
);
|
||||
results = results.map(v => v.replace(replacer, '$1').trim());
|
||||
|
||||
Reference in New Issue
Block a user