1 | var async = require('async'),
|
2 | cheerio = require('cheerio'),
|
3 | common = require('./common.js');
|
4 |
|
5 | function doLessJavascript(contents, file) {
|
6 | var $ = cheerio.load(contents);
|
7 | $("a[href^='http://'], a[href^='https://']")
|
8 | .attr("target", "_blank");
|
9 | $("a[href^='http://'], a[href^='https://']")
|
10 | .not(":has(> img:first-child)")
|
11 | .not('.noexternal')
|
12 | .addClass('external');
|
13 | $("a[href^='http://'], a[href^='https://']").each(function () {
|
14 | if ($(this).parents('.noexternal').length) {
|
15 | $(this).removeClass('external');
|
16 | }
|
17 | });
|
18 | $(".imageblock .title").each(function () {
|
19 | $(this).parents('.imageblock').first().addClass('hascaption');
|
20 | });
|
21 | $("a[href$='.pdf']")
|
22 | .not('.nopdf')
|
23 | .append(" (PDF)")
|
24 | .attr("target", "_blank");
|
25 | if (file && file.path) {
|
26 | var prefix = file.path.split("/")[0];
|
27 | if (prefix) {
|
28 | $("#menu-" + prefix).addClass('menu-selected');
|
29 | if (prefix !== 'posts') {
|
30 | $("title").append(" | " + prefix.charAt(0).toUpperCase() + prefix.slice(1));
|
31 | }
|
32 | }
|
33 | $('span.pullquote').each(function() {
|
34 | var parentParagraph = $(this).parent('p');
|
35 | parentParagraph.css('position', 'relative');
|
36 | var pulledQuote = $(this).clone().addClass('pulledquote');
|
37 | $(parentParagraph).prepend(pulledQuote);
|
38 | });
|
39 | }
|
40 | return $.html();
|
41 | };
|
42 |
|
43 | function lessjavascript(config) {
|
44 | return function(files, metalsmith, done) {
|
45 | var metadata = metalsmith.metadata();
|
46 | async.forEachOf(common.htmlfiles(files), function(file, filename, finished) {
|
47 | file.contents = new Buffer(doLessJavascript(file.contents, file));
|
48 | finished();
|
49 | }, function () {
|
50 | done();
|
51 | });
|
52 | }
|
53 | };
|
54 |
|
55 | exports = module.exports = lessjavascript;
|
56 | exports.doLessJavascript = doLessJavascript;
|