Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
pplaissy authored Mar 13, 2024
0 parents commit 70d152e
Show file tree
Hide file tree
Showing 35 changed files with 3,475 additions and 0 deletions.
82 changes: 82 additions & 0 deletions .eleventy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
const pluginWebc = require("@11ty/eleventy-plugin-webc");
const markdownIt = require("markdown-it");
const markdownItAttrs = require("markdown-it-attrs");
const { DateTime } = require("luxon");

module.exports = function(eleventyConfig) {
eleventyConfig.addPlugin(pluginWebc, {
components: "src/_includes/components/*.webc"
});

eleventyConfig.addPassthroughCopy("src/assets");

eleventyConfig.addJavaScriptFunction("postDate", (dateObj) => {
return DateTime.fromJSDate(dateObj).toLocaleString(DateTime.DATE_SHORT);
});

eleventyConfig.addJavaScriptFunction("url", (subUrl) => {
if (!subUrl.startsWith('/')) subUrl = '/' + subUrl;
return "https://code-crumbs.pplaissy.fr" + subUrl;
});

// eleventyConfig.addJavaScriptFunction("currentYear", () => {
// return DateTime.now().year;
// });

eleventyConfig.addCollection("posts", function(collectionApi) {
return collectionApi.getFilteredByTag("published").sort(function(a, b) {
return b.date - a.date; // sort by date - descending
});
});

let options = {
html: true,
breaks: true,
linkify: true
};

// set an instance of markdownIt
const md = new markdownIt(options).use(markdownItAttrs);
// declare a default link renderer
const defaultLinkRender = md.renderer.rules.link_open || function (tokens, idx, options, env, self) {
return self.renderToken(tokens, idx, options);
};
// set custom render function
md.renderer.rules.link_open = (tokens, idx, options, env, self) => {
const token = tokens[idx];
// get the class attribute
const classAttr = token.attrGet("class");
// if class attribute exists and contains the external link flag...
if (classAttr && classAttr.split(' ').includes("xlk")) {
// ...add the custom attributes
tokens[idx].attrSet('target', '_blank');
tokens[idx].attrJoin("rel", "noopener noreferrer");
}

// Pass the token to the default renderer.
return defaultLinkRender(tokens, idx, options, env, self);
};

md.renderer.rules.image = function (tokens, idx, options, env, self) {
const token = tokens[idx];
let src = token.attrGet('src');

// truncate paths for local images
token.attrSet('src', src.slice(3));
token.attrSet('alt', token.content);

return self.renderToken(tokens, idx, options)
};

// pass the markdown instance to eleventy config
eleventyConfig.setLibrary("md", md);

return {
dir: {
input: "src",
output: "_site",
includes: "_includes",
layouts: "_includes/layouts"
}
}
};
39 changes: 39 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

name: build 11ty site

on:
push:
branches: ["main"]

permissions:
contents: read
pages: write
id-token: write

concurrency:
group: "pages"
cancel-in-progress: false

jobs:

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- name: Install dependencies & build
run: |
npm install
npx @11ty/eleventy
- uses: actions/upload-pages-artifact@v3

# Deploy the Static Site to Public Repo (GitHub Pages)
- name: Deploy
uses: JamesIves/[email protected]
with:
token: ${{ secrets.SECRETNAME }}
repository-name: pplaissy/code-crumbs-site
branch: main # The branch the action should deploy to.
folder: _site # The folder the action should deploy.
single-commit: true
commit-message: "Deploy by source"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/node_modules
/_site
Empty file added .nojekyll
Empty file.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# code-crumbs
A tiny eleventy/webc static blog site
[code-crumbs](https://pplaissy.github.io/code-crumbs/)
Loading

0 comments on commit 70d152e

Please sign in to comment.