Skip to content

Commit a609f11

Browse files
author
LinuxJava7
committed
New website overhaul
0 parents  commit a609f11

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+4939
-0
lines changed

.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
indent_style = tab
5+
indent_size = 2
6+
end_of_line = lf
7+
insert_final_newline = true
8+
trim_trailing_whitespace = true
9+
charset = utf-8

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
content/feed/pretty-atom-feed.xsl linguist-vendored

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
_site/
2+
node_modules/
3+
.cache

.nojekyll

Whitespace-only changes.

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
20

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017–2024 Zach Leatherman @zachleat
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# eleventy-base-blog v9
2+
3+
A starter repository showing how to build a blog with the [Eleventy](https://www.11ty.dev/) site generator (using the [v3.0 release](https://github.com/11ty/eleventy/releases/tag/v3.0.0)).
4+
5+
## Getting Started
6+
7+
* [Want a more generic/detailed getting started guide?](https://www.11ty.dev/docs/getting-started/)
8+
9+
1. Make a directory and navigate to it:
10+
11+
```
12+
mkdir my-blog-name
13+
cd my-blog-name
14+
```
15+
16+
2. Clone this Repository
17+
18+
```
19+
git clone https://github.com/11ty/eleventy-base-blog.git .
20+
```
21+
22+
_Optional:_ Review `eleventy.config.js` and `_data/metadata.js` to configure the site’s options and data.
23+
24+
3. Install dependencies
25+
26+
```
27+
npm install
28+
```
29+
30+
4. Run Eleventy
31+
32+
Generate a production-ready build to the `_site` folder:
33+
34+
```
35+
npx @11ty/eleventy
36+
```
37+
38+
Or build and host on a local development server:
39+
40+
```
41+
npx @11ty/eleventy --serve
42+
```
43+
44+
Or you can run [debug mode](https://www.11ty.dev/docs/debugging/) to see all the internals.
45+
46+
## Features
47+
48+
- Using [Eleventy v3](https://github.com/11ty/eleventy/releases/tag/v3.0.0) with zero-JavaScript output.
49+
- Content is exclusively pre-rendered (this is a static site).
50+
- Can easily [deploy to a subfolder without changing any content](https://www.11ty.dev/docs/plugins/html-base/)
51+
- All URLs are decoupled from the content’s location on the file system.
52+
- Configure templates via the [Eleventy Data Cascade](https://www.11ty.dev/docs/data-cascade/)
53+
- **Performance focused**: four-hundos Lighthouse score out of the box!
54+
- _0 Cumulative Layout Shift_
55+
- _0ms Total Blocking Time_
56+
- Local development live reload provided by [Eleventy Dev Server](https://www.11ty.dev/docs/dev-server/).
57+
- Content-driven [navigation menu](https://www.11ty.dev/docs/plugins/navigation/)
58+
- Fully automated [Image optimization](https://www.11ty.dev/docs/plugins/image/)
59+
- Zero-JavaScript output.
60+
- Support for modern image formats automatically (e.g. AVIF and WebP)
61+
- Processes images on-request during `--serve` for speedy local builds.
62+
- Prefers `<img>` markup if possible (single image format) but switches automatically to `<picture>` for multiple image formats.
63+
- Automated `<picture>` syntax markup with `srcset` and optional `sizes`
64+
- Includes `width`/`height` attributes to avoid [content layout shift](https://web.dev/cls/).
65+
- Includes `loading="lazy"` for native lazy loading without JavaScript.
66+
- Includes [`decoding="async"`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLImageElement/decoding)
67+
- Images can be co-located with blog post files.
68+
- Per page CSS bundles [via `eleventy-plugin-bundle`](https://github.com/11ty/eleventy-plugin-bundle).
69+
- Built-in [syntax highlighter](https://www.11ty.dev/docs/plugins/syntaxhighlight/) (zero-JavaScript output).
70+
- Draft content: use `draft: true` to mark any template as a draft. Drafts are **only** included during `--serve`/`--watch` and are excluded from full builds. This is driven by the `addPreprocessor` configuration API in `eleventy.config.js`. Schema validator will show an error if non-boolean value is set in data cascade.
71+
- Blog Posts
72+
- Automated next/previous links
73+
- Accessible deep links to headings
74+
- Generated Pages
75+
- Home, Archive, and About pages.
76+
- [Atom feed included (with easy one-line swap to use RSS or JSON](https://www.11ty.dev/docs/plugins/rss/)
77+
- `sitemap.xml`
78+
- Zero-maintenance tag pages ([View on the Demo](https://eleventy-base-blog.netlify.app/tags/))
79+
- Content not found (404) page
80+
81+
## Demos
82+
83+
- [Netlify](https://eleventy-base-blog.netlify.app/)
84+
- [Vercel](https://demo-base-blog.11ty.dev/)
85+
- [Cloudflare Pages](https://eleventy-base-blog-d2a.pages.dev/)
86+
- [Remix on Glitch](https://glitch.com/~11ty-eleventy-base-blog)
87+
- [GitHub Pages](https://11ty.github.io/eleventy-base-blog/)
88+
89+
## Deploy this to your own site
90+
91+
Deploy this Eleventy site in just a few clicks on these services:
92+
93+
- Read more about [Deploying an Eleventy project](https://www.11ty.dev/docs/deployment/) to the web.
94+
- [Deploy this to **Netlify**](https://app.netlify.com/start/deploy?repository=https://github.com/11ty/eleventy-base-blog)
95+
- [Deploy this to **Vercel**](https://vercel.com/import/project?template=11ty%2Feleventy-base-blog)
96+
- Look in `.github/workflows/gh-pages.yml.sample` for information on [Deploying to **GitHub Pages**](https://www.11ty.dev/docs/deployment/#deploy-an-eleventy-project-to-git-hub-pages).
97+
- [Try it out on **Stackblitz**](https://stackblitz.com/github/11ty/eleventy-base-blog)
98+
99+
### Implementation Notes
100+
101+
- `content/about/index.md` is an example of a content page.
102+
- `content/blog/` has the blog posts but really they can live in any directory. They need only the `posts` tag to be included in the blog posts [collection](https://www.11ty.dev/docs/collections/).
103+
- Use the `eleventyNavigation` key (via the [Eleventy Navigation plugin](https://www.11ty.dev/docs/plugins/navigation/)) in your front matter to add a template to the top level site navigation. This is in use on `content/index.njk` and `content/about/index.md`.
104+
- Content can be in _any template format_ (blog posts needn’t exclusively be markdown, for example). Configure your project’s supported templates in `eleventy.config.js` -> `templateFormats`.
105+
- 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.
106+
- This project uses three [Eleventy Layouts](https://www.11ty.dev/docs/layouts/):
107+
- `_includes/layouts/base.njk`: the top level HTML structure
108+
- `_includes/layouts/home.njk`: the home page template (wrapped into `base.njk`)
109+
- `_includes/layouts/post.njk`: the blog post template (wrapped into `base.njk`)
110+
- `_includes/postslist.njk` is a Nunjucks include and is a reusable component used to display a list of all the posts. `content/index.njk` has an example of how to use it.
111+
112+
#### Content Security Policy
113+
114+
If your site enforces a [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP) (as public-facing sites should), you have a few choices (pick one):
115+
116+
1. In `base.njk`, remove `<style>{% getBundle "css" %}</style>` and uncomment `<link rel="stylesheet" href="{% getBundleFileUrl "css" %}">`
117+
2. Configure the server with the CSP directive `style-src: 'unsafe-inline'` (less secure).

_config/filters.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { DateTime } from "luxon";
2+
import fs from 'fs';
3+
import path from 'path';
4+
import { fileURLToPath } from 'url';
5+
6+
const __filename = fileURLToPath(import.meta.url);
7+
const __dirname = path.dirname(__filename);
8+
9+
/** @param {import("@11ty/eleventy").UserConfig} eleventyConfig */
10+
export default function(eleventyConfig) {
11+
eleventyConfig.addFilter("readableDate", (dateObj, format, zone) => {
12+
// Formatting tokens for Luxon: https://moment.github.io/luxon/#/formatting?id=table-of-tokens
13+
return DateTime.fromJSDate(dateObj, { zone: zone || "utc" }).toFormat(format || "dd LLLL yyyy");
14+
});
15+
16+
eleventyConfig.addFilter("htmlDateString", (dateObj) => {
17+
// dateObj input: https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-date-string
18+
return DateTime.fromJSDate(dateObj, { zone: "utc" }).toFormat('yyyy-LL-dd');
19+
});
20+
21+
// Get the first `n` elements of a collection.
22+
eleventyConfig.addFilter("head", (array, n) => {
23+
if(!Array.isArray(array) || array.length === 0) {
24+
return [];
25+
}
26+
if( n < 0 ) {
27+
return array.slice(n);
28+
}
29+
30+
return array.slice(0, n);
31+
});
32+
33+
// Return the smallest number argument
34+
eleventyConfig.addFilter("min", (...numbers) => {
35+
return Math.min.apply(null, numbers);
36+
});
37+
38+
// Return the keys used in an object
39+
eleventyConfig.addFilter("getKeys", target => {
40+
return Object.keys(target);
41+
});
42+
43+
eleventyConfig.addFilter("filterTagList", function filterTagList(tags) {
44+
return (tags || []).filter(tag => ["all", "posts"].indexOf(tag) === -1);
45+
});
46+
47+
eleventyConfig.addFilter("sortAlphabetically", strings =>
48+
(strings || []).sort((b, a) => b.localeCompare(a))
49+
);
50+
51+
eleventyConfig.addFilter("inlineSvg", function(iconName) {
52+
if (!iconName) return '';
53+
54+
const iconPath = path.join(__dirname, '..', '_includes', 'icons', `${iconName}.svg`);
55+
56+
try {
57+
if (fs.existsSync(iconPath)) {
58+
const svg = fs.readFileSync(iconPath, 'utf8');
59+
return svg;
60+
}
61+
return '';
62+
} catch (err) {
63+
console.warn(`Could not load SVG icon: ${iconName}`, err);
64+
return '';
65+
}
66+
});
67+
}

_data/eleventyDataSchema.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { z } from "zod";
2+
import { fromZodError } from 'zod-validation-error';
3+
4+
export default function(data) {
5+
// Draft content, validate `draft` front matter
6+
let result = z.object({
7+
draft: z.boolean().or(z.undefined()),
8+
}).safeParse(data);
9+
10+
if(result.error) {
11+
throw fromZodError(result.error);
12+
}
13+
}

_data/metadata.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export default {
2+
title: "LinuxJava7's Website",
3+
url: "https://linuxjava7.dev/",
4+
language: "en",
5+
description: "I write random stuff",
6+
author: {
7+
name: "LinuxJava7",
8+
email: "",
9+
url: "https://linuxjava7.dev/about/",
10+
},
11+
};

0 commit comments

Comments
 (0)