Abstracted tag loading
Using the utility script.
This commit is contained in:
@ -111,22 +111,7 @@ try {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Load tag data from the database
|
// Load tag data from the database
|
||||||
try {
|
tagDbData = util.readTags();
|
||||||
tagDbData = objectFromPairs(
|
|
||||||
fs
|
|
||||||
.readFileSync('tag_database', 'utf8')
|
|
||||||
.split('\n')
|
|
||||||
.slice(0, -1)
|
|
||||||
.map(v => {
|
|
||||||
let data = v.split(':').slice(0, 2);
|
|
||||||
data[1] = data[1].split(',').map(t => t.trim());
|
|
||||||
return data;
|
|
||||||
})
|
|
||||||
);
|
|
||||||
} catch (err) {
|
|
||||||
console.log(`${chalk.red('ERROR!')} During tag database loading: ${err}`);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the output for the README file
|
// Create the output for the README file
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -28,28 +28,13 @@ const countOccurrences = (arr, value) => arr.reduce((a, v) => (v === value ? a +
|
|||||||
console.time('Tagger');
|
console.time('Tagger');
|
||||||
// Synchronously read all snippets and sort them as necessary (case-insensitive)
|
// Synchronously read all snippets and sort them as necessary (case-insensitive)
|
||||||
snippets = util.readSnippets(snippetsPath);
|
snippets = util.readSnippets(snippetsPath);
|
||||||
try {
|
// Load tag data from the database
|
||||||
tagDbData = objectFromPairs(
|
tagDbData = util.readTags();
|
||||||
fs
|
tagDbStats = Object.entries(tagDbData)
|
||||||
.readFileSync('tag_database', 'utf8')
|
.reduce((acc, val) => {
|
||||||
.split('\n')
|
val[1].forEach(v => acc.hasOwnProperty(v) ? acc[v]++ : (acc[v] = 1));
|
||||||
.slice(0, -1)
|
return acc;
|
||||||
.map(v => {
|
}, {});
|
||||||
let data = v.split(':').slice(0, 2);
|
|
||||||
data[1] = data[1].split(',').map(t => t.trim());
|
|
||||||
return data;
|
|
||||||
})
|
|
||||||
);
|
|
||||||
tagDbStats = Object.entries(tagDbData)
|
|
||||||
.reduce((acc, val) => {
|
|
||||||
val[1].forEach(v => acc.hasOwnProperty(v) ? acc[v]++ : (acc[v] = 1));
|
|
||||||
return acc;
|
|
||||||
}, {});
|
|
||||||
} catch (err) {
|
|
||||||
// Handle errors (hopefully not!)
|
|
||||||
console.log(`${chalk.red('ERROR!')} During tag database loading: ${err}`);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
// Update the listing of snippets in tag_database and log the statistics, along with missing scripts
|
// Update the listing of snippets in tag_database and log the statistics, along with missing scripts
|
||||||
try {
|
try {
|
||||||
for (let snippet of Object.entries(snippets))
|
for (let snippet of Object.entries(snippets))
|
||||||
|
|||||||
@ -23,4 +23,29 @@ const readSnippets = snippetsPath => {
|
|||||||
}
|
}
|
||||||
return snippets;
|
return snippets;
|
||||||
}
|
}
|
||||||
module.exports = {readSnippets};
|
// Used in `readTags`
|
||||||
|
const objectFromPairs = arr => arr.reduce((a, v) => ((a[v[0]] = v[1]), a), {});
|
||||||
|
// Load tag data from the database
|
||||||
|
const readTags = () => {
|
||||||
|
let tagDbData = {};
|
||||||
|
try {
|
||||||
|
tagDbData = objectFromPairs(
|
||||||
|
fs
|
||||||
|
.readFileSync('tag_database', 'utf8')
|
||||||
|
.split('\n')
|
||||||
|
.slice(0, -1)
|
||||||
|
.map(v => {
|
||||||
|
let data = v.split(':').slice(0, 2);
|
||||||
|
data[1] = data[1].split(',').map(t => t.trim());
|
||||||
|
return data;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
// Handle errors (hopefully not!)
|
||||||
|
console.log(`${chalk.red('ERROR!')} During tag database loading: ${err}`);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
return tagDbData;
|
||||||
|
}
|
||||||
|
module.exports = {readSnippets, readTags};
|
||||||
|
|||||||
@ -75,23 +75,7 @@ try {
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
// Load tag data from the database
|
// Load tag data from the database
|
||||||
try {
|
tagDbData = util.readTags();
|
||||||
tagDbData = objectFromPairs(
|
|
||||||
fs
|
|
||||||
.readFileSync('tag_database', 'utf8')
|
|
||||||
.split('\n')
|
|
||||||
.slice(0, -1)
|
|
||||||
.map(v => {
|
|
||||||
let data = v.split(':').slice(0, 2);
|
|
||||||
data[1] = data[1].split(',').map(t => t.trim());
|
|
||||||
return data;
|
|
||||||
})
|
|
||||||
);
|
|
||||||
} catch (err) {
|
|
||||||
// Handle errors (hopefully not!)
|
|
||||||
console.log(`${chalk.red('ERROR!')} During tag database loading: ${err}`);
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
// Create the output for the index.html file
|
// Create the output for the index.html file
|
||||||
try {
|
try {
|
||||||
// Add the start static part
|
// Add the start static part
|
||||||
|
|||||||
Reference in New Issue
Block a user