updated build script, probably still works fine

pull/388/head
tycrek 3 years ago
parent 1b38b947a8
commit 01d71c5789
No known key found for this signature in database
GPG Key ID: 25D74F3943625263

@ -24,7 +24,7 @@ const BUILD_SECTION = {
news: () => generatePublications('News articles', 'news'), news: () => generatePublications('News articles', 'news'),
lighterSide: () => readFile('md/_lighterSide.md'), lighterSide: () => readFile('md/_lighterSide.md'),
closingRemarks: () => readFile('md/_closingRemarks.md') closingRemarks: () => readFile('md/_closingRemarks.md')
} };
// Button that brings the user to the top of the page // Button that brings the user to the top of the page
const BACK_TO_TOP = '[![Back to top](https://img.shields.io/badge/Back%20to%20top-lightgrey?style=flat-square)](#index)'; const BACK_TO_TOP = '[![Back to top](https://img.shields.io/badge/Back%20to%20top-lightgrey?style=flat-square)](#index)';
@ -34,7 +34,7 @@ const BACK_TO_TOP = '[![Back to top](https://img.shields.io/badge/Back%20to%20to
*/ */
function __main__() { function __main__() {
// dgSectionData will be join at the end and represents the full contents of README.md // dgSectionData will be join at the end and represents the full contents of README.md
let dgSectionData = []; const dgSectionData = [];
// Add all the sections // Add all the sections
dgSectionData.push(BUILD_SECTION.header()); dgSectionData.push(BUILD_SECTION.header());
@ -56,7 +56,7 @@ function __main__() {
dgSectionData.push(BUILD_SECTION.closingRemarks()); dgSectionData.push(BUILD_SECTION.closingRemarks());
// Write to the README file // Write to the README file
fs.writeFileSync(path.join(__dirname, 'README.md'), dgSectionData.join(os.EOL + os.EOL)); fs.writeFileSync(path.join(__dirname, 'README.md'), dgSectionData.join(`${os.EOL}${os.EOL}`));
console.log('Done!'); console.log('Done!');
} }
@ -85,10 +85,10 @@ function generateCategorySection(header, data) {
if (!data) return ''; if (!data) return '';
// Set the header to HTML <h5> // Set the header to HTML <h5>
let categorySection = '## ' + header + os.EOL + BACK_TO_TOP + os.EOL + os.EOL; let categorySection = `## ${header}${os.EOL}${BACK_TO_TOP}${os.EOL}${os.EOL}`;
// Generate service sections for this category // Generate service sections for this category
Object.keys(data).forEach((key) => categorySection = categorySection.concat(generateServiceSection(data[key]) + os.EOL + os.EOL)); Object.keys(data).forEach((key) => categorySection = categorySection.concat(`${generateServiceSection(data[key])}${os.EOL}${os.EOL}`));
return categorySection; return categorySection;
} }
@ -100,18 +100,26 @@ function generateCategorySection(header, data) {
function generateServiceSection(data) { function generateServiceSection(data) {
// Start the section with an <h4> header // Start the section with an <h4> header
let serviceSection = `#### ${data[0].title + os.EOL + os.EOL}`; let serviceSection = `#### ${data[0].title + os.EOL + os.EOL}`;
// Prep section notes
let notes = os.EOL + ''; let notes = os.EOL + '';
// If there is data to be displayed, add the start of a Markdown table // If there is data to be displayed, add the start of a Markdown table
let tableHeader = `| Name | Eyes | Description |${os.EOL}| ---- | ---- | ----------- |${os.EOL}`; let tableHeader = `| Name | Eyes | Description |${os.EOL}| ---- | ---- | ----------- |${os.EOL}`;
if (data.filter(d => 'name' in d).length == 0) tableHeader = `No known alternatives.${os.EOL}`; if (data.filter((d) => 'name' in d).length === 0) tableHeader = `No known alternatives.${os.EOL}`;
// Add the header to the section body
serviceSection = serviceSection.concat(tableHeader); serviceSection = serviceSection.concat(tableHeader);
// Iterate over each alternative service and add it to the table // Iterate over each alternative service and add it to the table
data.forEach(item => { data.forEach((item) => {
// If the object has length one, it's either title or note // If the object has length one, it's either title or note
if (Object.keys(item).length == 1) { if (Object.keys(item).length == 1) {
if (!item.notes) return; if (!item.notes) return;
else item.notes.forEach((note) => notes = notes.concat(`- *${note.trim()}*${os.EOL}`)); else item.notes.forEach((note) => notes = notes.concat(`- *${note.trim()}*${os.EOL}`));
} else { } else {
// Build the cells for the table // Build the cells for the table
let name = `[${item.name}](${item.url})`; let name = `[${item.name}](${item.url})`;
let eyes = item.eyes ? `**${item.eyes}-eyes**` : ''; let eyes = item.eyes ? `**${item.eyes}-eyes**` : '';
@ -124,14 +132,13 @@ function generateServiceSection(data) {
if (item.repo) name = name.concat('<br/>', repoLink(item.repo)); if (item.repo) name = name.concat('<br/>', repoLink(item.repo));
// Build the row // Build the row
let tableItem = `| ${name} | ${eyes} | ${text} |`; let tableItem = `| ${name} | ${eyes} | ${text} |${os.EOL}`;
// Add the row to the table // Add the row to the table
serviceSection = serviceSection.concat(tableItem + os.EOL); serviceSection = serviceSection.concat(tableItem);
} }
}); });
return `${serviceSection}${notes}`;
return serviceSection + notes;
} }
/** /**
@ -148,9 +155,9 @@ function fdroidLink(appId) {
*/ */
function repoLink(repo) { function repoLink(repo) {
let repoURL = new URL(repo); let repoURL = new URL(repo);
let repoHost = path.basename(repoURL.hostname, path.extname(repoURL.hostname)) let repoHost = path.basename(repoURL.hostname, path.extname(repoURL.hostname));
if (repoHost.includes(".")) repoHost = path.extname(repoHost).replace(".", "") if (repoHost.includes(".")) repoHost = path.extname(repoHost).replace(".", "");
return `[![Repo](https://img.shields.io/badge/open-source-3DA639?style=flat-square&logo=${repoHost})](${repo})` return `[![Repo](https://img.shields.io/badge/open-source-3DA639?style=flat-square&logo=${repoHost})](${repo})`;
} }
/** /**
@ -159,7 +166,7 @@ function repoLink(repo) {
*/ */
function addonLink(link) { function addonLink(link) {
if (!link.includes('addons.mozilla.org')) return ''; if (!link.includes('addons.mozilla.org')) return '';
let addonId = link.split('/')[link.split('/').length - 1] let addonId = link.split('/')[link.split('/').length - 1];
return `![Mozilla Add-on](https://img.shields.io/amo/users/${addonId}?style=flat-square)`; return `![Mozilla Add-on](https://img.shields.io/amo/users/${addonId}?style=flat-square)`;
} }
@ -168,7 +175,7 @@ function addonLink(link) {
* @param {String|Number} date Date of publication * @param {String|Number} date Date of publication
*/ */
function dateBadge(date) { function dateBadge(date) {
return `![Published](https://img.shields.io/badge/${date.toString().replace(/\-/g, '--')}-informational?style=flat-square)` return `![Published](https://img.shields.io/badge/${date.toString().replace(/\-/g, '--')}-informational?style=flat-square)`;
} }
/** /**
@ -177,16 +184,13 @@ function dateBadge(date) {
function generateBrowserExtensions() { function generateBrowserExtensions() {
let extensions = `# Browser extensions${os.EOL + os.EOL}| Name | Description |${os.EOL}| ---- | ----------- |${os.EOL}`; let extensions = `# Browser extensions${os.EOL + os.EOL}| Name | Description |${os.EOL}| ---- | ----------- |${os.EOL}`;
let data = YAML.parse(fs.readFileSync(path.join(__dirname, 'yaml/browserExtensions.yml')).toString()); let data = YAML.parse(fs.readFileSync(path.join(__dirname, 'yaml/browserExtensions.yml')).toString());
data.forEach(item => { data.forEach((item) => {
let name = `[${item.name}](${item.url})`; let name = `[${item.name}](${item.url})`;
let text = item.text.trim(); let text = item.text.trim();
let badge = addonLink(item.url); let badge = addonLink(item.url);
let tableItem = `| ${name + ' ' + badge} | ${text} |${os.EOL}`;
let tableItem = `| ${name + ' ' + badge} | ${text} |`; extensions = extensions.concat(tableItem);
extensions = extensions.concat(tableItem + os.EOL);
}); });
return extensions; return extensions;
} }
@ -198,16 +202,13 @@ function generateBrowserExtensions() {
function generatePublications(title, filename) { function generatePublications(title, filename) {
let publications = `## ${title} ${os.EOL + BACK_TO_TOP + os.EOL + os.EOL}| Title | Published | Author |${os.EOL}| ----- | --------- | ------ |${os.EOL}`; let publications = `## ${title} ${os.EOL + BACK_TO_TOP + os.EOL + os.EOL}| Title | Published | Author |${os.EOL}| ----- | --------- | ------ |${os.EOL}`;
let data = YAML.parse(fs.readFileSync(path.join(__dirname, `yaml/${filename}.yml`)).toString()); let data = YAML.parse(fs.readFileSync(path.join(__dirname, `yaml/${filename}.yml`)).toString());
data.forEach(item => { data.forEach((item) => {
let name = `[${item.title}](${item.url})`; let name = `[${item.title}](${item.url})`;
let author = item.author.trim(); let author = item.author.trim();
let tableItem = `| ${name} | ${dateBadge(item.date)} | ${author} |${os.EOL}`;
let tableItem = `| ${name} | ${dateBadge(item.date)} | ${author} |`; publications = publications.concat(tableItem);
publications = publications.concat(tableItem + os.EOL);
}); });
return publications; return publications;
} }
__main__(); __main__();

Loading…
Cancel
Save