Skip to content

Commit

Permalink
Improve Pagination and Add *Some* CSS.
Browse files Browse the repository at this point in the history
  • Loading branch information
Reboot-Codes committed Jul 29, 2024
1 parent f9f0c4b commit df1f820
Show file tree
Hide file tree
Showing 21 changed files with 498 additions and 37 deletions.
17 changes: 17 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# The Modified MIT License

Copyright 2024-present by Reboot/Fitz, and Contributors.

Tl;dr (this is non-legally binding, and is only here as an abridged explanation of the following **binding** legal disclaimer under "License"): All source code is open to free reproduction and modification; we actually encourage you to use RCGI as a base/inspiration to build your own websites! All non-original content has its creator/author/license listed under "Acknowledgements". Have fun! `:]`

## License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software") with exception of dialogue (Text associated with actions (including but not limited to speaking, movement, physical interactions, etc) performed within the story (also known as the Software)), images, audio, and video; 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. All dialogue, images, audio, and video which do not have a separate license and/or author listed at the bottom of this document under "Acknowledgements" are under an all rights reserved license and require the express permission of Reboot/Fitz to be redistributed/modified. Redistribution/usage of the Software is 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.

## Acknowledgements

it's quite empty here...
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
# Reboot/Fitz's Site

![Last Commit](https://img.shields.io/github/last-commit/Reboot-Codes/new-rcgi) ![Repo Size](https://img.shields.io/github/languages/code-size/Reboot-Codes/new-rcgi?color=brightgreen) ![GitHub Actions Build Workflow Status](https://img.shields.io/github/actions/workflow/status/Reboot-Codes/new-rcgi/build.yml)

This is a remake of RCGI because it's kinda... jank. So, instead, we're using 11ty this go around.

## Build

Install dependencies with yarn and use `yarn build`. Simple as that! Eleventy will take care of building the site.

## Make Content

### Posts

To make a new post, just create it in `src/posts`. Give it a `title` in the front-matter, and everything else should be handled for you.

Tags automatically have pages generated.

### Projects

To make a project, decide on a project ID (referenced here as `$PROJECT_ID`), then on related posts, tag them with `project:$PROJECT_ID`.

In `src/projects`, make a page where the front-matter looks like the following:

```yaml
title: $PROJECT_TITLE
projectId: $PROJECT_ID
pagination:
data: collections.project:$PROJECT_ID
```
Where `$PROJECT_TITLE` is the pretty name for the project. The content of that page will be like a blurb displayed above the posts for that project.
56 changes: 55 additions & 1 deletion eleventy.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
const sass = require("sass");
const { feedPlugin } = require("@11ty/eleventy-plugin-rss");
const markdownIt = require("markdown-it");
const markdownItAnchor = require("markdown-it-anchor");
const timeToRead = require('eleventy-plugin-time-to-read');

module.exports = function (eleventyConfig) {
eleventyConfig.addTemplateFormats("scss");
const md = markdownIt({ "html": true }).use(markdownItAnchor, {
"level": 2,
permalink: markdownItAnchor.permalink.headerLink()
});
eleventyConfig.setLibrary("md", md);

eleventyConfig.addTemplateFormats("scss");
// Creates the extension for use
eleventyConfig.addExtension("scss", {
outputFileExtension: "css", // optional, default: "html"
Expand All @@ -19,6 +27,10 @@ module.exports = function (eleventyConfig) {
},
});

eleventyConfig.addPlugin(timeToRead, {
speed: '250 words a minute'
});

eleventyConfig.addCollection(
"allPosts",
function (collectionApi) {
Expand Down Expand Up @@ -60,6 +72,48 @@ module.exports = function (eleventyConfig) {
return str.slice(num);
});

// Return all the tags used in a collection
eleventyConfig.addFilter("getAllTags", collection => {
let tagSet = new Set();
for(let item of collection) {
(item.data.tags || []).forEach(tag => tagSet.add(tag));
}
return Array.from(tagSet);
});

eleventyConfig.addFilter("filterTagList", function filterTagList(tags) {
return (tags || []).filter(tag => ["all", "post", "allPosts", "project", "allProjects"].indexOf(tag) === -1).filter((tag) => (!(tag.startsWith("project:"))));
});

const parseDate = (str) => {
if (str instanceof Date) {
return str;
}
return Date.parse(str);
};

const formatPart = (part, date) =>
new Intl.DateTimeFormat("en", part).format(date);

eleventyConfig.addFilter("formatDate", async (obj) => {
if (!obj) {
return "";
}
const date = parseDate(obj);

const month = formatPart({ month: "short" }, date);
const day = formatPart({ day: "numeric" }, date);
const year = formatPart({ year: "numeric" }, date);
const hours = date.getUTCHours();
const minutes = date.getUTCMinutes();

if (hours != 0 && minutes != 0) {
return `${month} ${day}, ${year} - ${hours}:${minutes} UTC`;
}

return `${month} ${day}, ${year}`;
});

return {
dir: {
input: "src",
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
{
"name": "rebootfitz-newsite",
"scripts": {
"build": "eleventy"
"build": "eleventy",
"dev": "eleventy --serve"
},
"dependencies": {
"@11ty/eleventy": ">=3.0.0-alpha.15",
"@11ty/eleventy-plugin-rss": "^2.0.2",
"eleventy-plugin-time-to-read": "^1.3.0",
"markdown-it": "^14.1.0",
"markdown-it-anchor": "^9.0.1",
"sass": "^1.77.8"
}
}
5 changes: 3 additions & 2 deletions src/_includes/components/navigation.njk
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<nav>
<nav id="navbar" class="nav-bar">
<a id="section-title" class="nav-title" href="/">{% include "copywriting/sectionTitle.njk" %}</a>
{% for navLink in nav %}
<a href="{{ navLink.href }}">{{ navLink.title }}</a>
<a id="nav-item-{{ loop.index }}" class="nav-item" href="{{ navLink.href }}">{{ navLink.title }}</a>
{% endfor %}
</nav>
57 changes: 49 additions & 8 deletions src/_includes/components/pagination.njk
Original file line number Diff line number Diff line change
@@ -1,11 +1,52 @@
{% if ((pagination.hrefs | length) > 1) %}
<ul>
<li><a href="{{ pagination.hrefs[0] }}"{% if page.url == pagination.hrefs[0] %} aria-current="page"{% endif %}>First</a></li>
<li>{% if pagination.href.previous %}<a href="{{ pagination.href.previous }}">Previous</a>{% else %}Previous{% endif %}</li>
{%- for pageEntry in pagination.pages %}
<li><a href="{{ pagination.hrefs[ loop.index0 ] }}"{% if page.url == pagination.hrefs[ loop.index0 ] %} aria-current="page"{% endif %}>Page {{ loop.index }}</a></li>
{%- endfor %}
<li>{% if pagination.href.next %}<a href="{{ pagination.href.next }}">Next</a>{% else %}Next{% endif %}</li>
<li><a href="{{ pagination.hrefs[(pagination.hrefs | length) - 1] }}"{% if page.url == pagination.hrefs[-1] %} aria-current="page"{% endif %}>Last</a></li>
<ul {% if paginationId %}id="{{ paginationId }}"{% endif %} class="pagination{% if paginationClasses %}{{ paginationClasses }}{% endif %}">
<li {% if paginationId %}id="{{ paginationId }}-first"{% endif %} class="pagination-first pagination-control"{% if page.url == pagination.hrefs[0] %} aria-current="page">First{% else %}><a href="{{ pagination.hrefs[0] }}">First</a>{% endif %}</li>
<li {% if paginationId %}id="{{ paginationId }}-previous"{% endif %} class="pagination-previous pagination-control"{% if pagination.href.previous %}><a href="{{ pagination.href.previous }}">Previous</a>{% else %} aria-current="page">Previous{% endif %}</li>


{% if ((pagination.pages | length) > 5) %}
{% if pagination.pageNumber == 0 %}
<li{% if paginationId %}id="{{ paginationId }}-item-{{ pagination.pageNumber + 1 }}" {% endif %} class="pagination-item pagination-control" aria-current="page">Page {{ pagination.pageNumber + 1 }}</li>
<li{% if paginationId %}id="{{ paginationId }}-item-{{ pagination.pageNumber + 2 }}" {% endif %} class="pagination-item pagination-control"><a href="{{ pagination.hrefs[pagination.pageNumber + 1] }}">Page {{ pagination.pageNumber + 2 }}</a></li>
<li{% if paginationId %}id="{{ paginationId }}-item-{{ pagination.pageNumber + 3 }}" {% endif %} class="pagination-item pagination-control"><a href="{{ pagination.hrefs[pagination.pageNumber + 2] }}">Page {{ pagination.pageNumber + 3 }}</a></li>
<li{% if paginationId %}id="{{ paginationId }}-item-{{ pagination.pageNumber + 4 }}" {% endif %} class="pagination-item pagination-control"><a href="{{ pagination.hrefs[pagination.pageNumber + 3] }}">Page {{ pagination.pageNumber + 4 }}</a></li>
<li{% if paginationId %}id="{{ paginationId }}-item-{{ pagination.pageNumber + 5 }}" {% endif %} class="pagination-item pagination-control"><a href="{{ pagination.hrefs[pagination.pageNumber + 4] }}">Page {{ pagination.pageNumber + 5 }}</a></li>

{% elif pagination.pageNumber == 1 %}
<li{% if paginationId %}id="{{ paginationId }}-item-{{ pagination.pageNumber }}" {% endif %} class="pagination-item pagination-control"><a href="{{ pagination.hrefs[pagination.pageNumber - 1] }}">Page {{ pagination.pageNumber }}</a></li>
<li{% if paginationId %}id="{{ paginationId }}-item-{{ pagination.pageNumber + 1 }}" {% endif %} class="pagination-item pagination-control" aria-current="page">Page {{ pagination.pageNumber + 1 }}</li>
<li{% if paginationId %}id="{{ paginationId }}-item-{{ pagination.pageNumber + 2 }}" {% endif %} class="pagination-item pagination-control"><a href="{{ pagination.hrefs[pagination.pageNumber + 1] }}">Page {{ pagination.pageNumber + 2 }}</a></li>
<li{% if paginationId %}id="{{ paginationId }}-item-{{ pagination.pageNumber + 3 }}" {% endif %} class="pagination-item pagination-control"><a href="{{ pagination.hrefs[pagination.pageNumber + 2] }}">Page {{ pagination.pageNumber + 3 }}</a></li>
<li{% if paginationId %}id="{{ paginationId }}-item-{{ pagination.pageNumber + 4 }}" {% endif %} class="pagination-item pagination-control"><a href="{{ pagination.hrefs[pagination.pageNumber + 3] }}">Page {{ pagination.pageNumber + 4 }}</a></li>

{% elif pagination.pageNumber == ((pagination.pages | length) - 2) %}
<li{% if paginationId %}id="{{ paginationId }}-item-{{ pagination.pageNumber - 2 }}" {% endif %} class="pagination-item pagination-control"><a href="{{ pagination.hrefs[pagination.pageNumber - 3] }}">Page {{ pagination.pageNumber - 2 }}</a></li>
<li{% if paginationId %}id="{{ paginationId }}-item-{{ pagination.pageNumber - 1 }}" {% endif %} class="pagination-item pagination-control"><a href="{{ pagination.hrefs[pagination.pageNumber - 2] }}">Page {{ pagination.pageNumber - 1 }}</a></li>
<li{% if paginationId %}id="{{ paginationId }}-item-{{ pagination.pageNumber }}" {% endif %} class="pagination-item pagination-control"><a href="{{ pagination.hrefs[pagination.pageNumber - 1] }}">Page {{ pagination.pageNumber }}</a></li>
<li{% if paginationId %}id="{{ paginationId }}-item-{{ pagination.pageNumber + 1 }}" {% endif %} class="pagination-item pagination-control" aria-current="page">Page {{ pagination.pageNumber + 1 }}</li>
<li{% if paginationId %}id="{{ paginationId }}-item-{{ pagination.pageNumber + 2 }}" {% endif %} class="pagination-item pagination-control"><a href="{{ pagination.hrefs[pagination.pageNumber + 1] }}">Page {{ pagination.pageNumber + 2 }}</a></li>

{% elif pagination.pageNumber == ((pagination.pages | length) - 1) %}
<li{% if paginationId %}id="{{ paginationId }}-item-{{ pagination.pageNumber - 3 }}" {% endif %} class="pagination-item pagination-control"><a href="{{ pagination.hrefs[pagination.pageNumber - 4] }}">Page {{ pagination.pageNumber - 3 }}</a></li>
<li{% if paginationId %}id="{{ paginationId }}-item-{{ pagination.pageNumber - 2 }}" {% endif %} class="pagination-item pagination-control"><a href="{{ pagination.hrefs[pagination.pageNumber - 3] }}">Page {{ pagination.pageNumber - 2 }}</a></li>
<li{% if paginationId %}id="{{ paginationId }}-item-{{ pagination.pageNumber - 1 }}" {% endif %} class="pagination-item pagination-control"><a href="{{ pagination.hrefs[pagination.pageNumber - 2] }}">Page {{ pagination.pageNumber - 1 }}</a></li>
<li{% if paginationId %}id="{{ paginationId }}-item-{{ pagination.pageNumber }}" {% endif %} class="pagination-item pagination-control"><a href="{{ pagination.hrefs[pagination.pageNumber - 1] }}">Page {{ pagination.pageNumber }}</a></li>
<li{% if paginationId %}id="{{ paginationId }}-item-{{ pagination.pageNumber + 1 }}" {% endif %} class="pagination-item pagination-control" aria-current="page">Page {{ pagination.pageNumber + 1 }}</li>

{% else %}
<li{% if paginationId %}id="{{ paginationId }}-item-{{ pagination.pageNumber - 1 }}" {% endif %} class="pagination-item pagination-control"><a href="{{ pagination.hrefs[pagination.pageNumber - 2] }}">Page {{ pagination.pageNumber - 1 }}</a></li>
<li{% if paginationId %}id="{{ paginationId }}-item-{{ pagination.pageNumber }}" {% endif %} class="pagination-item pagination-control"><a href="{{ pagination.hrefs[pagination.pageNumber - 1] }}">Page {{ pagination.pageNumber }}</a></li>
<li{% if paginationId %}id="{{ paginationId }}-item-{{ pagination.pageNumber + 1 }}" {% endif %} class="pagination-item pagination-control" aria-current="page">Page {{ pagination.pageNumber + 1 }}</li>
<li{% if paginationId %}id="{{ paginationId }}-item-{{ pagination.pageNumber + 2 }}" {% endif %} class="pagination-item pagination-control"><a href="{{ pagination.hrefs[pagination.pageNumber + 1] }}">Page {{ pagination.pageNumber + 2 }}</a></li>
<li{% if paginationId %}id="{{ paginationId }}-item-{{ pagination.pageNumber + 3 }}" {% endif %} class="pagination-item pagination-control"><a href="{{ pagination.hrefs[pagination.pageNumber + 2] }}">Page {{ pagination.pageNumber + 3 }}</a></li>
{% endif %}
{% else %}
{% for pageEntry in pagination.pages %}
<li{% if paginationId %}id="{{ paginationId }}-item-{{ loop.index }}" {% endif %} class="pagination-item pagination-control" {% if page.url == pagination.hrefs[loop.index - 1] %} aria-current="page">Page {{ loop.index }}{% else %}><a href="{{ pagination.hrefs[ loop.index0 ] }}">Page {{ loop.index }}</a>{% endif %}</li>
{% endfor %}
{% endif %}

<li{% if paginationId %}id="{{ paginationId }}-next" {% endif %} class="pagination-next pagination-control"{% if pagination.href.next %}><a href="{{ pagination.href.next }}">Next</a>{% else %} aria-current="page">Next{% endif %}</li>
<li{% if paginationId %}id="{{ paginationId }}-last" {% endif %} class="pagination-last pagination-control"{% if page.url == pagination.hrefs[(pagination.hrefs | length) - 1] %} aria-current="page">Last{% else %}><a href="{{ pagination.hrefs[(pagination.hrefs | length) - 1] }}">Last</a>{% endif %}</li>
</ul>
{% endif %}
1 change: 1 addition & 0 deletions src/_includes/copywriting/sectionTitle.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% if isBlog %}{{ generalData.blog.title }}{% elif isProject %}{{ generalData.workshop.title }}{% else %}{{ generalData.site.title }}{% endif %}
1 change: 1 addition & 0 deletions src/_includes/copywriting/title.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% include "copywriting/sectionTitle.njk" %}{% if title %} - {{ title }}{% endif %}
7 changes: 3 additions & 4 deletions src/_includes/layouts/base.njk
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
---
isBlog: false
useContainer: true
---

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
{% if isBlog %}{{ generalData.blog.title }}{% elif isProject %}{{ generalData.workshop.title }}{% else %}{{ generalData.site.title }}{% endif %}{% if title %} - {{ title }}{% endif %}
</title>
<title>{% include "copywriting/title.njk" %}</title>
<link rel="stylesheet" href="/styles/global.css" />
</head>
<body>
{% include "components/navigation.njk" %}
<main>
<main id="page-content" {% if useContainer %}class="page-container"{% endif %}>
{{ content | safe }}
</main>
{% include "components/footer.njk" %}
Expand Down
30 changes: 18 additions & 12 deletions src/_includes/layouts/post.njk
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
---
layout: base.njk
isBlog: true
useContainer: true
---

<h1>{{ title }}</h1>

<p>on {{ page.date | formatDate }}, takes {{ content | timeToRead }} to read.</p>

<h2>Tags</h2>
{% if ((tags | length) > 1) %}
<h2>Tags</h2>
<ul>
{% for tag in tags %}
{% if tag != "post" %}
{% if (tag | startsWith("project:")) %}
<li><a href="/projects/{{ tag | strSlice(8) }}">Project: {% for project in collections.allProjects %}{% if (project.data.projectId == (tag | strSlice(8))) %}{{ project.data.title }}{% endif %}{% endfor %}</a></li>
{% else %}
<li><a>{{ tag }}</a></li>
{% endif %}
<ul>
{% for tag in tags %}
{% if tag != "post" %}
{% if (tag | startsWith("project:")) %}
<li><a href="/projects/{{ tag | strSlice(8) }}">Project: {% for project in collections.allProjects %}{% if (project.data.projectId == (tag | strSlice(8))) %}{{ project.data.title }}{% endif %}{% endfor %}</a></li>
{% else %}
<li><a href="/tags/{{ tag }}">{{ tag }}</a></li>
{% endif %}
{% endfor %}
</ul>
{% endif %}
{% endfor %}
</ul>
{% else %}
<p>No tags</p>
{% endif %}

<div id="post-content" class="content">
{{ content | safe }}

<div>
1 change: 1 addition & 0 deletions src/_includes/layouts/project.njk
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ layout: base.njk
isProject: true
pagination:
size: 2
useContainer: true
---

<h1>{{ title }}</h1>
Expand Down
27 changes: 23 additions & 4 deletions src/posts.njk
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,34 @@ title: Posts
isBlog: true
pagination:
data: collections.allPosts
size: 2
size: 1
---

<h1>{{ title }}</h1>
<h1>The DIY Bog</h1>

<h2>Tags</h2>

{% if ((collections.all | getAllTags | filterTagList) | length) > 0 %}
<p>Find posts of a specific subect.</p>

<ul>
{% for tag in collections.all | getAllTags | filterTagList %}
<li><a href="/tags/{{ tag }}/">{{ tag }}</a></li>
{% endfor %}
</ul>
{% else %}
<p>No tags yet...</p>
{% endif %}

<h2>Posts</h2>

<div id="posts-list" class="post-list">
{%- for item in pagination.items %}
<li><a href="{{ item.page.url }}">{{ item.data.title }}</a></li>
<article id="post-{{ loop.index }}" class="post">
<a href="{{ item.page.url }}">{{ item.data.title }}</a>
<p>on {{ item.page.date | formatDate }}, takes {{ item.content | timeToRead }} to read.</p>
</article>
{% endfor -%}
</ul>
</div>

{% include "components/pagination.njk" %}
6 changes: 5 additions & 1 deletion src/posts/post-1.md

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src/posts/post-3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: Post 3
---

ahgsd
5 changes: 5 additions & 0 deletions src/posts/post-4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: Post 4
---

ahgsd
5 changes: 5 additions & 0 deletions src/posts/post-5.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: Post 5
---

ahgsd
Loading

0 comments on commit df1f820

Please sign in to comment.