diff --git a/.eleventy.js b/.eleventy.js index 302b1ba..88efed7 100644 --- a/.eleventy.js +++ b/.eleventy.js @@ -1,50 +1,17 @@ const { DateTime } = require("luxon"); -const metadata = require("./_data/metadata.json"); -const absoluteUrl = require("./_src/AbsoluteUrl"); -const HtmlToAbsoluteUrls = require("./_src/HtmlToAbsoluteUrls"); -const syntaxHighlighter = require("./_src/eleventy-liquidjs-tag-highlight-prismjs"); - -function dateToISO(dateObj) { - return DateTime.fromJSDate(dateObj).toISO({ includeOffset: true, suppressMilliseconds: true }); -} +const pluginRss = require("@11ty/eleventy-plugin-rss"); +const pluginSyntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight"); module.exports = function(eleventyConfig) { + eleventyConfig.addPlugin(pluginRss); + eleventyConfig.addPlugin(pluginSyntaxHighlight); + eleventyConfig.addLayoutAlias("post", "layouts/post.njk"); - eleventyConfig.addFilter("rssLastUpdatedDate", collection => { - if( !collection.length ) { - throw new Error( "Collection is empty in lastUpdatedDate filter." ); - } - // Newest date in the collection - return dateToISO(collection[ collection.length - 1 ].date); - }); - - eleventyConfig.addFilter("rssDate", dateObj => { - return dateToISO(dateObj); - }); - eleventyConfig.addFilter("readableDate", dateObj => { return DateTime.fromJSDate(dateObj).toFormat("dd LLL yyyy"); }); - eleventyConfig.addNunjucksFilter("absoluteUrl", function(href, base) { - return absoluteUrl(href, base); - }); - - eleventyConfig.addNunjucksFilter("htmlToAbsoluteUrls", function(htmlContent, base, callback) { - if(!htmlContent) { - callback(null, ""); - return; - } - - HtmlToAbsoluteUrls(htmlContent, base).then(result => { - callback(null, result.html); - }); - }, true); - - // compatibility with existing {% highlight js %} and others - eleventyConfig.addLiquidTag("highlight", syntaxHighlighter); - // only content in the `posts/` directory eleventyConfig.addCollection("posts", function(collection) { return collection.getAllSorted().filter(function(item) { diff --git a/_src/AbsoluteUrl.js b/_src/AbsoluteUrl.js deleted file mode 100644 index f85fcc0..0000000 --- a/_src/AbsoluteUrl.js +++ /dev/null @@ -1,5 +0,0 @@ -const { URL } = require("url"); - -module.exports = function(url, base) { - return (new URL(url, base)).toString() -}; \ No newline at end of file diff --git a/_src/HighlightLines.js b/_src/HighlightLines.js deleted file mode 100644 index f3e0d50..0000000 --- a/_src/HighlightLines.js +++ /dev/null @@ -1,33 +0,0 @@ -class HighlightLines { - constructor(rangeStr) { - this.highlights = this.convertRangeToHash(rangeStr); - } - - convertRangeToHash(rangeStr) { - let hash = {}; - if( !rangeStr ) { - return hash; - } - - let ranges = rangeStr.split(",").map(function(range) { - return range.trim(); - }); - - for(let range of ranges) { - let startFinish = range.split('-'); - let start = parseInt(startFinish[0], 10); - let end = parseInt(startFinish[1] || start, 10); - - for( let j = start, k = end; j<=k; j++ ) { - hash[j] = true; - } - } - return hash; - } - - isHighlighted(lineNumber) { - return !!this.highlights[lineNumber] - } -} - -module.exports = HighlightLines; \ No newline at end of file diff --git a/_src/HtmlToAbsoluteUrls.js b/_src/HtmlToAbsoluteUrls.js deleted file mode 100644 index 2b219e0..0000000 --- a/_src/HtmlToAbsoluteUrls.js +++ /dev/null @@ -1,22 +0,0 @@ -const posthtml = require('posthtml'); -const urls = require('posthtml-urls') -const absoluteUrl = require("./AbsoluteUrl"); - -module.exports = function(htmlContent, base) { - let options = { - eachURL: function(url, attr, element) { - url = url.trim(); - - // #anchor in-page - if( url.indexOf("#") === 0 ) { - return url; - } - - return absoluteUrl(url, base); - } - }; - - let modifier = posthtml().use(urls(options)); - - return modifier.process(htmlContent); -}; diff --git a/_src/LiquidHighlight.js b/_src/LiquidHighlight.js deleted file mode 100644 index ebaa79c..0000000 --- a/_src/LiquidHighlight.js +++ /dev/null @@ -1,83 +0,0 @@ -const HighlightLines = require('./HighlightLines'); - -class LiquidHighlight { - constructor(liquidEngine) { - this.liquidEngine = liquidEngine; - this.hooks = []; - this.classHooks = []; - } - - addHook(hookFunction) { - this.hooks.push(hookFunction); - } - - addClassHook(hookFunction) { - this.classHooks.push(hookFunction); - } - - getObject() { - let ret = function(highlighter) { - return { - parse: function(tagToken, remainTokens) { - let split = tagToken.args.split(" "); - - this.language = split[0]; - this.highlights = new HighlightLines(split.length === 2 ? split[1] : ""); - this.highlightsAdd = new HighlightLines(split.length === 3 ? split[1] : ""); - this.highlightsRemove = new HighlightLines(split.length === 3 ? split[2] : ""); - - this.tokens = []; - - var stream = highlighter.liquidEngine.parser.parseStream(remainTokens); - - stream - .on('token', token => { - if (token.name === 'endhighlight') { - stream.stop(); - } else { - this.tokens.push(token); - } - }) - .on('end', x => { - throw new Error("tag highlight not closed"); - }); - - stream.start(); - }, - render: function(scope, hash) { - let tokens = this.tokens.map(token => token.raw); - let tokenStr = tokens.join('').trim(); - - for( let hook of highlighter.hooks ) { - tokenStr = hook.call(this, this.language, tokenStr); - } - - let lines = tokenStr.split("\n").map(function(line, j) { - let classHookClasses = []; - for( let classHook of highlighter.classHooks ) { - let ret = classHook(this.language, line, j); - if( ret ) { - classHookClasses.push(ret); - } - } - - return '
` + lines.join("") + "
");
- }
- };
- };
-
- return ret(this);
- }
-}
-
-module.exports = LiquidHighlight;
\ No newline at end of file
diff --git a/_src/eleventy-liquidjs-tag-highlight-plain.js b/_src/eleventy-liquidjs-tag-highlight-plain.js
deleted file mode 100644
index bd153c3..0000000
--- a/_src/eleventy-liquidjs-tag-highlight-plain.js
+++ /dev/null
@@ -1,16 +0,0 @@
-const LiquidHighlight = require( "./LiquidHighlight" );
-
-module.exports = function(liquidEngine) {
- let highlight = new LiquidHighlight(liquidEngine);
-
- highlight.addClassHook(function(language, line) {
- if( language === "dir" ) {
- // has trailing slash
- if( line.match(/\/$/) !== null ) {
- return "highlight-line-isdir";
- }
- }
- });
-
- return highlight.getObject();
-};
\ No newline at end of file
diff --git a/_src/eleventy-liquidjs-tag-highlight-prismjs.js b/_src/eleventy-liquidjs-tag-highlight-prismjs.js
deleted file mode 100644
index c0a128c..0000000
--- a/_src/eleventy-liquidjs-tag-highlight-prismjs.js
+++ /dev/null
@@ -1,12 +0,0 @@
-const Prism = require('prismjs');
-const LiquidHighlight = require( "./LiquidHighlight" );
-
-module.exports = function(liquidEngine) {
- let highlight = new LiquidHighlight(liquidEngine);
-
- highlight.addHook(function(language, htmlStr, lines) {
- return Prism.highlight(htmlStr, Prism.languages[ language ]);
- });
-
- return highlight.getObject();
-};
\ No newline at end of file
diff --git a/_src/test/HtmlToAbsoluteUrlsTest.js b/_src/test/HtmlToAbsoluteUrlsTest.js
deleted file mode 100644
index e039e4e..0000000
--- a/_src/test/HtmlToAbsoluteUrlsTest.js
+++ /dev/null
@@ -1,9 +0,0 @@
-import test from "ava";
-import htmlToAbsUrls from "../HtmlToAbsoluteUrls.js";
-
-test("Changes a link href", async t => {
- t.is((await htmlToAbsUrls(`Hello`, "http://example.com/")).html, `Hello`);
- t.is((await htmlToAbsUrls(`Hello`, "http://example.com/")).html, `Hello`);
- t.is((await htmlToAbsUrls(``, "http://example.com/")).html, ``);
- t.is((await htmlToAbsUrls(`Hello`, "http://example.com/")).html, `Hello`);
-});
diff --git a/package.json b/package.json
index 3f55c35..ecb8ac2 100644
--- a/package.json
+++ b/package.json
@@ -22,21 +22,10 @@
},
"homepage": "https://github.com/11ty/eleventy-base-blog#readme",
"dependencies": {
- "@11ty/eleventy": "0.2.12",
+ "@11ty/eleventy": "0.2.13",
+ "@11ty/eleventy-plugin-rss": "^1.0.1",
+ "@11ty/eleventy-plugin-syntaxhighlight": "^1.0.0",
"luxon": "^0.3.1",
- "posthtml": "^0.11.2",
- "posthtml-urls": "^1.0.0",
"prismjs": "^1.10.0"
- },
- "devDependencies": {
- "ava": "^0.25.0"
- },
- "ava": {
- "files": [
- "_src/test/*.js"
- ],
- "source": [
- "_src/**/*.{js,jsx}"
- ]
}
}
diff --git a/posts/firstpost.md b/posts/firstpost.md
index 9e67b31..c6d5e67 100644
--- a/posts/firstpost.md
+++ b/posts/firstpost.md
@@ -11,10 +11,10 @@ Bring to the table win-win survival strategies to ensure proactive domination. A
Capitalize on low hanging fruit to identify a ballpark value added activity to beta test. Override the digital divide with additional clickthroughs from DevOps. Nanotechnology immersion along the information highway will close the loop on focusing solely on the bottom line.
-{% highlight js 2-3 %}
+{% highlight-plain js 2-3 %}
// this is a command
function myCommand() {
let counter = 0;
counter++;
}
-{% endhighlight %}
\ No newline at end of file
+{% endhighlight %}
diff --git a/posts/secondpost.md b/posts/secondpost.md
index e6019f9..45797ee 100644
--- a/posts/secondpost.md
+++ b/posts/secondpost.md
@@ -7,6 +7,9 @@ layout: layouts/post.njk
---
Leverage agile frameworks to provide a robust synopsis for high level overviews. Iterative approaches to corporate strategy foster collaborative thinking to further the overall value proposition. Organically grow the holistic world view of disruptive innovation via workplace diversity and empowerment.
+First post
+Third post
+
Bring to the table win-win survival strategies to ensure proactive domination. At the end of the day, going forward, a new normal that has evolved from generation X is on the runway heading towards a streamlined cloud solution. User generated content in real-time will have multiple touchpoints for offshoring.
-Capitalize on low hanging fruit to identify a ballpark value added activity to beta test. Override the digital divide with additional clickthroughs from DevOps. Nanotechnology immersion along the information highway will close the loop on focusing solely on the bottom line.
\ No newline at end of file
+Capitalize on low hanging fruit to identify a ballpark value added activity to beta test. Override the digital divide with additional clickthroughs from DevOps. Nanotechnology immersion along the information highway will close the loop on focusing solely on the bottom line.