Add id to each link

This commit is contained in:
Julien Bisconti 2018-04-22 13:51:56 +02:00
parent 6656c3dc3b
commit a321d2c048
2 changed files with 16 additions and 1 deletions

View File

@ -2,6 +2,7 @@ const fs = require('fs');
const showdown = require('showdown');
const cheerio = require('cheerio');
const Parcel = require('parcel-bundler');
const camelCase = require('camelcase');
process.env.NODE_ENV = 'production';
@ -47,7 +48,20 @@ const includeReadme = ({
console.log('Merging files...');
const $ = cheerio.load(indexTemplate);
$('#md').append(converter.makeHtml(markdown));
$('a').each((i, elem) => {
// console.log(elem);
$(elem).attr(
'id',
`${camelCase(
$(elem)
.attr('href')
.replace(/\/|\.|:|#/g, ''),
{
pascalCase: true,
},
)}-${i}`,
);
});
console.log('Writing index.html');
fs.writeFileSync(dest, $.html(), 'utf8');
console.log('DONE 👍');

View File

@ -19,6 +19,7 @@
},
"homepage": "https://github.com/veggiemonk/awesome-docker#readme",
"dependencies": {
"camelcase": "^5.0.0",
"cheerio": "^1.0.0-rc.2",
"critical": "^1.1.1",
"parcel-bundler": "^1.6.2",