generated from 11ty/eleventy-base-blog
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit db5102f
Showing
35 changed files
with
988 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
charset = utf-8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
const { DateTime } = require("luxon"); | ||
const fs = require("fs"); | ||
const pluginRss = require("@11ty/eleventy-plugin-rss"); | ||
const pluginSyntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight"); | ||
const pluginNavigation = require("@11ty/eleventy-navigation"); | ||
const markdownIt = require("markdown-it"); | ||
const markdownItAnchor = require("markdown-it-anchor"); | ||
|
||
module.exports = function(eleventyConfig) { | ||
eleventyConfig.addPlugin(pluginRss); | ||
eleventyConfig.addPlugin(pluginSyntaxHighlight); | ||
eleventyConfig.addPlugin(pluginNavigation); | ||
|
||
eleventyConfig.setDataDeepMerge(true); | ||
|
||
eleventyConfig.addLayoutAlias("post", "layouts/post.njk"); | ||
|
||
eleventyConfig.addFilter("readableDate", dateObj => { | ||
return DateTime.fromJSDate(dateObj, {zone: 'utc'}).toFormat("dd LLL yyyy"); | ||
}); | ||
|
||
// https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-date-string | ||
eleventyConfig.addFilter('htmlDateString', (dateObj) => { | ||
return DateTime.fromJSDate(dateObj, {zone: 'utc'}).toFormat('yyyy-LL-dd'); | ||
}); | ||
|
||
// Get the first `n` elements of a collection. | ||
eleventyConfig.addFilter("head", (array, n) => { | ||
if( n < 0 ) { | ||
return array.slice(n); | ||
} | ||
|
||
return array.slice(0, n); | ||
}); | ||
|
||
eleventyConfig.addCollection("tagList", function(collection) { | ||
let tagSet = new Set(); | ||
collection.getAll().forEach(function(item) { | ||
if( "tags" in item.data ) { | ||
let tags = item.data.tags; | ||
|
||
tags = tags.filter(function(item) { | ||
switch(item) { | ||
// this list should match the `filter` list in tags.njk | ||
case "all": | ||
case "nav": | ||
case "post": | ||
case "posts": | ||
return false; | ||
} | ||
|
||
return true; | ||
}); | ||
|
||
for (const tag of tags) { | ||
tagSet.add(tag); | ||
} | ||
} | ||
}); | ||
|
||
// returning an array in addCollection works in Eleventy 0.5.3 | ||
return [...tagSet]; | ||
}); | ||
|
||
eleventyConfig.addPassthroughCopy("img"); | ||
eleventyConfig.addPassthroughCopy("css"); | ||
|
||
/* Markdown Overrides */ | ||
let markdownLibrary = markdownIt({ | ||
html: true, | ||
breaks: true, | ||
linkify: true | ||
}).use(markdownItAnchor, { | ||
permalink: true, | ||
permalinkClass: "direct-link", | ||
permalinkSymbol: "#" | ||
}); | ||
eleventyConfig.setLibrary("md", markdownLibrary); | ||
|
||
// Browsersync Overrides | ||
eleventyConfig.setBrowserSyncConfig({ | ||
callbacks: { | ||
ready: function(err, browserSync) { | ||
const content_404 = fs.readFileSync('_site/404.html'); | ||
|
||
browserSync.addMiddleware("*", (req, res) => { | ||
// Provides the 404 content without redirect. | ||
res.write(content_404); | ||
res.end(); | ||
}); | ||
}, | ||
}, | ||
ui: false, | ||
ghostMode: false | ||
}); | ||
|
||
return { | ||
templateFormats: [ | ||
"md", | ||
"njk", | ||
"html", | ||
"liquid" | ||
], | ||
|
||
// If your site lives in a different subdirectory, change this. | ||
// Leading or trailing slashes are all normalized away, so don’t worry about those. | ||
|
||
// If you don’t have a subdirectory, use "" or "/" (they do the same thing) | ||
// This is only used for link URLs (it does not affect your file structure) | ||
// Best paired with the `url` filter: https://www.11ty.dev/docs/filters/url/ | ||
|
||
// You can also pass this in on the command line using `--pathprefix` | ||
// pathPrefix: "/", | ||
|
||
markdownTemplateEngine: "liquid", | ||
htmlTemplateEngine: "njk", | ||
dataTemplateEngine: "njk", | ||
|
||
// These are all optional, defaults are shown: | ||
dir: { | ||
input: ".", | ||
includes: "_includes", | ||
data: "_data", | ||
output: "_site" | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
README.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# These are supported funding model platforms | ||
open_collective: 11ty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
_site/ | ||
node_modules/ | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
language: node_js | ||
node_js: | ||
- 8 | ||
before_script: | ||
- npm install @11ty/eleventy -g | ||
script: eleventy --pathprefix="/eleventy-base-blog/" | ||
deploy: | ||
local-dir: _site | ||
provider: pages | ||
skip-cleanup: true | ||
github-token: $GITHUB_TOKEN # Set in travis-ci.org dashboard, marked secure | ||
keep-history: true | ||
on: | ||
branch: master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
layout: layouts/home.njk | ||
permalink: 404.html | ||
eleventyExcludeFromCollections: true | ||
--- | ||
# Content not found. | ||
|
||
Go <a href="{{ '/' | url }}">home</a>. | ||
|
||
{% comment %} | ||
Read more: https://www.11ty.dev/docs/quicktips/not-found/ | ||
|
||
This will work for both GitHub pages and Netlify: | ||
|
||
* https://help.github.com/articles/creating-a-custom-404-page-for-your-github-pages-site/ | ||
* https://www.netlify.com/docs/redirects/#custom-404 | ||
{% endcomment %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2018 Zach Leatherman @zachleat | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# eleventy-base-blog | ||
|
||
A starter repository showing how to build a blog with the [Eleventy](https://github.com/11ty/eleventy) static site generator. | ||
|
||
[](https://travis-ci.org/11ty/eleventy-base-blog) | ||
|
||
## Demos | ||
|
||
* [Netlify](https://eleventy-base-blog.netlify.com/) | ||
* [GitHub Pages](https://11ty.github.io/eleventy-base-blog/) | ||
* [Remix on Glitch](https://glitch.com/~11ty-eleventy-base-blog) | ||
|
||
## Deploy this to your own site | ||
|
||
These builders are amazing—try them out to get your own Eleventy site in a few clicks! | ||
|
||
* [Get your own Eleventy web site on Netlify](https://app.netlify.com/start/deploy?repository=https://github.com/11ty/eleventy-base-blog) | ||
* [Get your own Eleventy web site on Vercel](https://vercel.com/import/project?template=11ty%2Feleventy-base-blog) | ||
|
||
## Getting Started | ||
|
||
### 1. Clone this Repository | ||
|
||
``` | ||
git clone https://github.com/11ty/eleventy-base-blog.git my-blog-name | ||
``` | ||
|
||
|
||
### 2. Navigate to the directory | ||
|
||
``` | ||
cd my-blog-name | ||
``` | ||
|
||
Specifically have a look at `.eleventy.js` to see if you want to configure any Eleventy options differently. | ||
|
||
### 3. Install dependencies | ||
|
||
``` | ||
npm install | ||
``` | ||
|
||
### 4. Edit _data/metadata.json | ||
|
||
### 5. Run Eleventy | ||
|
||
``` | ||
npx eleventy | ||
``` | ||
|
||
Or build and host locally for local development | ||
``` | ||
npx eleventy --serve | ||
``` | ||
|
||
Or build automatically when a template changes: | ||
``` | ||
npx eleventy --watch | ||
``` | ||
|
||
Or in debug mode: | ||
``` | ||
DEBUG=* npx eleventy | ||
``` | ||
|
||
### Implementation Notes | ||
|
||
* `about/index.md` shows how to add a content page. | ||
* `posts/` has the blog posts but really they can live in any directory. They need only the `post` tag to be added to this collection. | ||
* Add the `nav` tag to add a template to the top level site navigation. For example, this is in use on `index.njk` and `about/index.md`. | ||
* Content can be any template format (blog posts needn’t be markdown, for example). Configure your supported templates in `.eleventy.js` -> `templateFormats`. | ||
* Because `css` and `png` are listed in `templateFormats` but are not supported template types, any files with these extensions will be copied without modification to the output (while keeping the same directory structure). | ||
* The blog post feed template is in `feed/feed.njk`. This is also a good example of using a global data files in that it uses `_data/metadata.json`. | ||
* This example uses three layouts: | ||
* `_includes/layouts/base.njk`: the top level HTML structure | ||
* `_includes/layouts/home.njk`: the home page template (wrapped into `base.njk`) | ||
* `_includes/layouts/post.njk`: the blog post template (wrapped into `base.njk`) | ||
* `_includes/postlist.njk` is a Nunjucks include and is a reusable component used to display a list of all the posts. `index.njk` has an example of how to use it. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"title": "Your Blog Name", | ||
"url": "https://example.com/", | ||
"description": "I am writing about my experiences as a naval navel-gazer.", | ||
"feed": { | ||
"subtitle": "I am writing about my experiences as a naval navel-gazer.", | ||
"filename": "feed.xml", | ||
"path": "/feed/feed.xml", | ||
"id": "https://example.com/" | ||
}, | ||
"jsonfeed": { | ||
"path": "/feed/feed.json", | ||
"url": "https://example.com/feed/feed.json" | ||
}, | ||
"author": { | ||
"name": "Your Name Here", | ||
"email": "[email protected]", | ||
"url": "https://example.com/about-me/" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>{{ title or metadata.title }}</title> | ||
<meta name="description" content="{{ description or metadata.description }}"> | ||
<link rel="stylesheet" href="{{ '/css/index.css' | url }}"> | ||
<link rel="stylesheet" href="{{ '/css/prism-base16-monokai.dark.css' | url }}"> | ||
<link rel="alternate" href="{{ metadata.feed.path | url }}" type="application/atom+xml" title="{{ metadata.title }}"> | ||
<link rel="alternate" href="{{ metadata.jsonfeed.path | url }}" type="application/json" title="{{ metadata.title }}"> | ||
</head> | ||
<body> | ||
<header> | ||
<h1 class="home"><a href="{{ '/' | url }}">{{ metadata.title }}</a></h1> | ||
|
||
{#- Read more about `eleventy-navigation` at https://www.11ty.dev/docs/plugins/navigation/ #} | ||
<ul class="nav"> | ||
{%- for entry in collections.all | eleventyNavigation %} | ||
<li class="nav-item{% if entry.url == page.url %} nav-item-active{% endif %}"><a href="{{ entry.url | url }}">{{ entry.title }}</a></li> | ||
{%- endfor %} | ||
</ul> | ||
</header> | ||
|
||
<main{% if templateClass %} class="{{ templateClass }}"{% endif %}> | ||
|
||
<!-- Delete this message --> | ||
<div class="warning"> | ||
<ol> | ||
<li>Edit the <code>_data/metadata.json</code> with your blog’s information.</li> | ||
<li>(Optional) Edit <code>.eleventy.js</code> with your <a href="https://www.11ty.dev/docs/config/">configuration preferences</a>.</li> | ||
<li>Delete this message from <code>_includes/layouts/base.njk</code>.</li> | ||
</ol> | ||
<p><em>This is an <a href="https://www.11ty.dev/">Eleventy project</a> created from the <a href="https://github.com/11ty/eleventy-base-blog"><code>eleventy-base-blog</code> repo</a>.</em></p> | ||
</div> | ||
<!-- Stop deleting --> | ||
|
||
{{ content | safe }} | ||
</main> | ||
|
||
<footer></footer> | ||
|
||
<!-- Current page: {{ page.url | url }} --> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
layout: layouts/base.njk | ||
templateClass: tmpl-home | ||
--- | ||
{{ content | safe }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
layout: layouts/base.njk | ||
templateClass: tmpl-post | ||
--- | ||
<h1>{{ title }}</h1> | ||
|
||
{{ content | safe }} | ||
|
||
<hr> | ||
<ul> | ||
{%- set nextPost = collections.posts | getNextCollectionItem(page) %} | ||
{%- if nextPost %}<li>Next: <a href="{{ nextPost.url | url }}">{{ nextPost.data.title }}</a></li>{% endif %} | ||
{%- set previousPost = collections.posts | getPreviousCollectionItem(page) %} | ||
{%- if previousPost %}<li>Previous: <a href="{{ previousPost.url | url }}">{{ previousPost.data.title }}</a></li>{% endif %} | ||
</ul> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<ol reversed class="postlist" style="counter-reset: start-from {{ (postslistCounter or postslist.length) + 1 }}"> | ||
{% for post in postslist | reverse %} | ||
<li class="postlist-item{% if post.url == url %} postlist-item-active{% endif %}"> | ||
<a href="{{ post.url | url }}" class="postlist-link">{% if post.data.title %}{{ post.data.title }}{% else %}<code>{{ post.url }}</code>{% endif %}</a> | ||
<time class="postlist-date" datetime="{{ post.date | htmlDateString }}">{{ post.date | readableDate }}</time> | ||
{% for tag in post.data.tags %} | ||
{%- if collections.tagList.indexOf(tag) != -1 -%} | ||
{% set tagUrl %}/tags/{{ tag }}/{% endset %} | ||
<a href="{{ tagUrl | url }}" class="post-tag">{{ tag }}</a> | ||
{%- endif -%} | ||
{% endfor %} | ||
</li> | ||
{% endfor %} | ||
</ol> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
layout: layouts/post.njk | ||
title: About Me | ||
templateClass: tmpl-post | ||
eleventyNavigation: | ||
key: About Me | ||
order: 3 | ||
--- | ||
|
||
I am a person that writes stuff. |
Oops, something went wrong.