Skip to content

Commit

Permalink
Cleaned up v2.0 status
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Jan 23, 2023
1 parent 00f8281 commit 65feb1c
Show file tree
Hide file tree
Showing 30 changed files with 117 additions and 279 deletions.
2 changes: 1 addition & 1 deletion en/404.md → 404.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
layout: layouts/home.webc
layout: layouts/home.njk
permalink: 404.html
eleventyExcludeFromCollections: true
---
Expand Down
16 changes: 7 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# eleventy-base-blog

A starter repository showing how to build a (multi-language friendly) blog with the [Eleventy](https://github.com/11ty/eleventy) static site generator.
A starter repository showing how to build a blog with the [Eleventy](https://github.com/11ty/eleventy) site generator.

[![Build Status](https://travis-ci.org/11ty/eleventy-base-blog.svg?branch=master)](https://travis-ci.org/11ty/eleventy-base-blog)

Expand Down Expand Up @@ -33,7 +33,7 @@ git clone https://github.com/11ty/eleventy-base-blog.git my-blog-name
cd my-blog-name
```

Specifically have a look at `.eleventy.js` to see if you want to configure any Eleventy options differently.
Specifically have a look at `eleventy.config.js` to see if you want to configure any Eleventy options differently.

### 3. Install dependencies

Expand Down Expand Up @@ -63,14 +63,12 @@ DEBUG=Eleventy* npx @11ty/eleventy

### Implementation Notes

- `en` is the folder for content (written using the primary language for project, here we’re using English)
- `en/about/index.md` is an example of an English content page.
- `en/blog/` has the English blog posts but really they can live in any directory. They need only the `post` tag to be included in the blog posts [collection](https://www.11ty.dev/docs/collections/).
- To localize a blog post you will need to add a top level folder for that language (`es` for Spanish, `ja` for Japanese, `en-us` for American English) and match the rest of the file path to the primary language folder. For example `en/blog/my-post.md` could have `ja/blog/my-post.md` or `es/blog/my-post.md`. Read more about [best practices for organizing files for internationalization (i18n) in Eleventy projects](https://www.11ty.dev/docs/i18n/).
- Use the `eleventyNavigation` key in your front matter to add a template to the top level site navigation. For example, this is in use on `index.njk` and `about/index.md`.
- `about/index.md` is an example of a content page.
- `blog/` has the blog posts but really they can live in any directory. They need only the `post` tag to be included in the blog posts [collection](https://www.11ty.dev/docs/collections/).
- Use the `eleventyNavigation` key in your front matter to add a template to the top level site navigation. This is in use on `index.njk` and `about/index.md`.
- This makes use of the [Eleventy Navigation plugin](https://www.11ty.dev/docs/plugins/navigation/)
- Content can be any template format (blog posts needn’t be markdown, for example). Configure your supported templates in `.eleventy.js` -> `templateFormats`.
- The `public` folder in your input directory will be copied to the output folder (via `addPassthroughCopy()` in the `.eleventy.js` file). This means `./public/css/*` will live at `./_site/css/*` after your build completes. [When using `--serve` this behavior is emulated](/docs/copy/#passthrough-during-serve) (the files will not show up in `_site`).
- Content can be any template format (blog posts needn’t be markdown, for example). Configure your supported templates in `eleventy.config.js` -> `templateFormats`.
- The `public` folder in your input directory will be copied to the output folder (via `addPassthroughCopy` in the `eleventy.config.js` file). This means `./public/css/*` will live at `./_site/css/*` after your build completes.
- 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 project uses three layouts:
- `_includes/layouts/base.njk`: the top level HTML structure
Expand Down
24 changes: 0 additions & 24 deletions _includes/components/infobox.webc

This file was deleted.

5 changes: 0 additions & 5 deletions _includes/components/syntax-highlight/syntax-highlight.webc

This file was deleted.

33 changes: 13 additions & 20 deletions _includes/layouts/base.njk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!doctype html>
<html lang="{{ lang or metadata.language }}">
<html lang="{{ metadata.language }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
Expand All @@ -10,34 +10,27 @@
{#- <meta name="generator" content="{{ eleventy.generator }}"> #}

<link rel="stylesheet" href="/css/index.css">
<style>
{{ page.url | webcGetCss | safe }}
</style>
<link rel="stylesheet" href="/css/prism-okaidia.css">
<link rel="stylesheet" href="/css/prism-diff.css">

<link rel="alternate" href="/feed/feed.xml" type="application/atom+xml" title="{{ metadata.title }}">
<link rel="alternate" href="/feed/feed.json" type="application/json" title="{{ metadata.title }}">

{%- set alternateUrls = page.url | locale_links %}
{% if alternateUrls.length %}
<link rel="alternate" hreflang="{{ lang or metadata.language }}" href="{{ page.url | htmlBaseUrl(metadata.url) }}">
{%- for link in alternateUrls %}
<link rel="alternate" hreflang="{{ link.lang }}" href="{{ link.url | htmlBaseUrl(metadata.url) }}">
{%- endfor %}
{%- endif %}
</head>
<body>
<header>
<h1 class="home"><a href="/">{{ 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 }}">{{ entry.title | i18n }}</a></li>
{%- endfor %}
</ul>
</header>

<main{% if templateClass %} class="{{ templateClass }}"{% endif %}>
<nav>
<ul class="nav">
{%- for entry in collections.all | eleventyNavigation %}
<li class="nav-item"><a href="{{ entry.url }}"{% if entry.url == page.url %} aria-current="page"{% endif %}>{{ entry.title }}</a></li>
{%- endfor %}
</ul>
</nav>
</header>

<main>
{{ content | safe }}
</main>

Expand Down
12 changes: 6 additions & 6 deletions _includes/layouts/home.webc → _includes/layouts/home.njk
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
---
layout: layouts/base.njk
templateClass: tmpl-home
---
<!-- Delete this message -->
<infobox>
<div class="message-box">
<link rel="stylesheet" href="/css/message-box.css">
<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/home.webc</code>.</li>
<li>(Optional) Edit <code>eleventy.config.js</code> with your <a href="https://www.11ty.dev/docs/config/">configuration preferences</a>.</li>
<li>Delete this message from <code>_includes/layouts/home.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>
</infobox>
</div>
<!-- Stop deleting -->

<template @raw="content" webc:nokeep></template>
{{ content | safe }}
19 changes: 2 additions & 17 deletions _includes/layouts/post.njk
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
---
layout: layouts/base.njk
templateClass: tmpl-post
---
<h1>{{ title }}</h1>

Expand All @@ -16,27 +15,13 @@ templateClass: tmpl-post

<hr>

{% set i18nLinks = page.url | locale_links %}
{% if i18nLinks.length %}
<ul>
<li>
{{ "i18n.also" | i18n }}
{%- for link in i18nLinks %}
<a href="{{ link.url }}" lang="{{ link.lang }}" hreflang="{{ link.lang }}">{{ link.label }}</a>
{%- if not loop.last %},{% endif %}
{%- endfor -%}
</li>
</ul>
{% endif %}

{%- if collections.posts %}
{# these filters are locale-aware in 2.0.0-canary.14 #}
{%- set previousPost = collections.posts | getPreviousCollectionItem %}
{%- set nextPost = collections.posts | getNextCollectionItem %}
{%- if nextPost or previousPost %}
<ul>
{%- if previousPost %}<li>{{ "i18n.previous" | i18n }}: <a href="{{ previousPost.url }}">{{ previousPost.data.title }}</a></li>{% endif %}
{%- if nextPost %}<li>{{ "i18n.next" | i18n }}: <a href="{{ nextPost.url }}">{{ nextPost.data.title }}</a></li>{% endif %}
{%- if previousPost %}<li>Previous: <a href="{{ previousPost.url }}">{{ previousPost.data.title }}</a></li>{% endif %}
{%- if nextPost %}<li>Next: <a href="{{ nextPost.url }}">{{ nextPost.data.title }}</a></li>{% endif %}
</ul>
{%- endif %}
{%- endif %}
9 changes: 9 additions & 0 deletions about/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
layout: layouts/base.njk
eleventyNavigation:
key: About Me
order: 3
---
# About Me

I am a person that writes stuff.
5 changes: 2 additions & 3 deletions en/blog.njk → blog.njk
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
---
layout: layouts/home.webc
layout: layouts/home.njk
eleventyNavigation:
key: nav.archive
key: Archive
order: 2
---

<h1>Archive</h1>

{% set postslist = collections.posts %}
Expand Down
File renamed without changes.
6 changes: 2 additions & 4 deletions en/blog/firstpost.md → blog/firstpost.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ Leverage agile frameworks to provide a robust synopsis for high level overviews.

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.

{{ "/" | locale_url }}

## Section Header

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.

<script webc:is="syntax-highlight" @syntax="diff-js">
```diff-js
// this is a command
function myCommand() {
+ let counter = 0;
Expand All @@ -25,4 +23,4 @@ Capitalize on low hanging fruit to identify a ballpark value added activity to b
// Test with a line break above this line.
console.log('Test');
</script>
```
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions en/blog/thirdpost.md → blog/thirdpost.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ tags:
---
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.

<script webc:is="syntax-highlight" @syntax="js">
```js
// this is a command
function myCommand() {
let counter = 0;
Expand All @@ -17,7 +17,7 @@ function myCommand() {

// Test with a line break above this line.
console.log('Test');
</script>
```

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.

Expand Down
76 changes: 22 additions & 54 deletions eleventy.config.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
const { DateTime } = require("luxon");
const rosetta = require("rosetta");
const markdownItAnchor = require("markdown-it-anchor");

const pluginRss = require("@11ty/eleventy-plugin-rss");
const pluginSyntaxHighlight = require("@11ty/eleventy-plugin-syntaxhighlight");
const pluginNavigation = require("@11ty/eleventy-navigation");
const pluginWebc = require("@11ty/eleventy-plugin-webc");

const {
EleventyRenderPlugin,
EleventyI18nPlugin,
EleventyHtmlBasePlugin
} = require("@11ty/eleventy");

const languageStrings = require("./i18n.js");
const { EleventyHtmlBasePlugin } = require("@11ty/eleventy");

module.exports = function(eleventyConfig) {
eleventyConfig.ignores.add("README.md");
Expand All @@ -22,23 +13,18 @@ module.exports = function(eleventyConfig) {
// For example, `./public/css/` ends up in `_site/css/`
eleventyConfig.addPassthroughCopy({
"./public/": "/",
"./node_modules/prismjs/themes/prism-okaidia.css": "/css/prism-okaidia.css"
});

// If your passthrough copy gets heavy and cumbersome, add this line
// to emulate the file copy on the dev server. Learn more: https://www.11ty.dev/docs/copy/#emulate-passthrough-copy-during-serve
// eleventyConfig.setServerPassthroughCopyBehavior("passthrough");

// Add plugins
eleventyConfig.addPlugin(pluginRss);
eleventyConfig.addPlugin(pluginSyntaxHighlight);
eleventyConfig.addPlugin(pluginNavigation);
eleventyConfig.addPlugin(EleventyHtmlBasePlugin);
eleventyConfig.addPlugin(EleventyRenderPlugin);

eleventyConfig.addPlugin(pluginWebc, {
components: "./_includes/components/**/*.webc"
});

eleventyConfig.addPlugin(EleventyI18nPlugin, {
defaultLanguage: "en",
errorMode: "allow-fallback",
});

eleventyConfig.addFilter("readableDate", (dateObj, format = "dd LLLL yyyy") => {
return DateTime.fromJSDate(dateObj, {zone: 'utc'}).toFormat(format);
Expand Down Expand Up @@ -79,7 +65,7 @@ module.exports = function(eleventyConfig) {
return (tags || []).filter(tag => ["all", "nav", "post", "posts"].indexOf(tag) === -1);
});

// Customize Markdown library and settings:
// Customize Markdown library settings:
eleventyConfig.amendLibrary("md", mdLib => {
mdLib.use(markdownItAnchor, {
permalink: markdownItAnchor.permalink.ariaHidden({
Expand All @@ -88,28 +74,10 @@ module.exports = function(eleventyConfig) {
symbol: "#",
}),
level: [1,2,3,4],
slugify: eleventyConfig.getFilter("slug")
slugify: eleventyConfig.getFilter("slugify")
});
});

// Override @11ty/eleventy-dev-server defaults (used only with --serve)
eleventyConfig.setServerOptions({
showVersion: true,
});

// i18n filter using Rosetta
const rosettaLib = rosetta(languageStrings);

eleventyConfig.addFilter("i18n", function (key, lang) {
const I18N_PREFIX = "i18n.";
if(key.startsWith(I18N_PREFIX)) {
key = key.slice(I18N_PREFIX.length);
}
// depends on page.lang in 2.0.0-canary.14+
let page = this.page || this.ctx?.page || this.context?.environments?.page || {};
return rosettaLib.t(key, {}, lang || page.lang);
});

return {
// Control which files Eleventy will process
// e.g.: *.md, *.njk, *.html, *.liquid
Expand All @@ -126,26 +94,26 @@ module.exports = function(eleventyConfig) {
// Pre-process *.html files with: (default: `liquid`)
htmlTemplateEngine: "njk",

// -----------------------------------------------------------------
// If your site deploys to a subdirectory, change `pathPrefix`.
// Don’t worry about leading and trailing slashes, we normalize these.

// 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`

// Optional (default is shown)
pathPrefix: "/",
// -----------------------------------------------------------------

// These are all optional (defaults are shown):
dir: {
input: ".",
includes: "_includes",
data: "_data",
output: "_site"
}

// -----------------------------------------------------------------
// Optional:

// If your site deploys to a subdirectory, change `pathPrefix`.
// Read more: https://www.11ty.dev/docs/config/#deploy-to-a-subdirectory-with-a-path-prefix

// When paired with the HTML <base> plugin https://www.11ty.dev/docs/plugins/html-base/
// it will transform any absolute URLs in your HTML to include this
// folder name and does **not** affect where things go in the output folder.

// Optional (default is shown)
// pathPrefix: "/",
// -----------------------------------------------------------------
};
};
11 changes: 0 additions & 11 deletions en/about/index.md

This file was deleted.

Loading

0 comments on commit 65feb1c

Please sign in to comment.