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