[Chore] Update extractor for 30web

This commit is contained in:
Angelos Chalaris
2019-11-06 19:05:35 +02:00
parent aa8b71b0cc
commit 80f3a24222
7 changed files with 23 additions and 12 deletions

View File

@ -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
};