Skip to content

Commit

Permalink
Merge pull request #44 from estrategias-adaptativas/eleventy
Browse files Browse the repository at this point in the history
Migra do Jekyll para o Eleventy
  • Loading branch information
p3palazzo authored May 6, 2024
2 parents 31f91d7 + fdb3cd5 commit 6bdb20d
Show file tree
Hide file tree
Showing 191 changed files with 53,343 additions and 2,171 deletions.
115 changes: 115 additions & 0 deletions .eleventy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/****************
* Filters {{{1 *
****************/
// First create variables that require() any packages we need
// const plugin = require('some-eleventy-plugin-package');
const { DateTime } = require('luxon');
const w3DateFilter = require('./src/filters/w3-date-filter.js');
const yaml = require('js-yaml');
const nodePandoc = require('node-pandoc');
const { EleventyHtmlBasePlugin } = require("@11ty/eleventy");
const fs = require("fs");
/********************************
* eleventyConfig function {{{1 *
********************************/
// Use module.exports to export a configuration funcion.
// This is a standard function in Node.js projects
module.exports = function(eleventyConfig) {
// Run any code needed including built-in 11ty methods
/*************************
* Passthrough copy {{{2 *
*************************/
// Copy assets/ to _site/assets
eleventyConfig.addPassthroughCopy(".gitattributes");
eleventyConfig.addPassthroughCopy("src/assets");
eleventyConfig.addPassthroughCopy({"node_modules/bootstrap-icons/icons": "assets/icons"});
eleventyConfig.addPassthroughCopy({"node_modules/bootstrap-icons/bootstrap-icons.svg": "assets/bootstrap-icons.svg"});
// emulate passthrough during --serve:
eleventyConfig.setServerPassthroughCopyBehavior("passthrough");
/*****************
* Markdown {{{2 *
*****************/
async function convertMarkdownToHtml(markdown, args) {
return new Promise((resolve, reject) => {
nodePandoc(markdown, '-d _data/defaults.yml', (err, result) => {
if (err) {
console.error(`Pandoc error: ${err.message}`);
resolve(result);
} else {
resolve(result);
}
});
});
}
eleventyConfig.setLibrary("md", {
render: async function(content) {
return await convertMarkdownToHtml(content);
}
});
/*************************
* Activate plugins {{{2 *
*************************/
// Call filters defined outside this function
eleventyConfig.addFilter("dateFilter", (dateObj) => {
return DateTime.fromJSDate(dateObj).setZone("utc").setLocale('pt').toLocaleString(DateTime.DATE_SHORT);
});
eleventyConfig.addFilter('w3DateFilter', w3DateFilter);
eleventyConfig.addDataExtension('yml, yaml', contents => yaml.load(contents));
eleventyConfig.addPlugin(EleventyHtmlBasePlugin);
/***********************
* Layout aliases {{{2 *
***********************/
eleventyConfig.addLayoutAlias("base", "layouts/base.njk");
eleventyConfig.addLayoutAlias("home", "layouts/home.njk");
eleventyConfig.addLayoutAlias("single", "layouts/base.njk");
eleventyConfig.addLayoutAlias("publication", "layouts/posts.njk");
eleventyConfig.addLayoutAlias("splash", "layouts/splash.njk");
eleventyConfig.addLayoutAlias("archive", "layouts/archive.njk");
eleventyConfig.addLayoutAlias("categories", "layouts/categories.njk");
/****************************
* Dynamic collections {{{2 *
****************************/
// Set the collection to reverse chronological order
//eleventyConfig.addCollection("post", (collection) => {
//return collection.getFilteredByTag("post").reverse();
//});
eleventyConfig.addCollection("produtos", function(collection) {
// Read the YAML file
const fileContent = fs.readFileSync("src/_data/produtos.yaml", "utf8");
// Parse YAML into JavaScript object
const data = yaml.load(fileContent);
// Extract the 'references' array from the data
const produtos = data.references || [];
// Convert the 'issued' field into a JavaScript Date object
produtos.forEach(produto => {
if (typeof produto.issued[0].month == 'undefined') {
produto.yearOnly = true;
produto.issued[0].month = 01;
}
if (typeof produto.issued[0].day == 'undefined') {
produto.issued[0].day = 01;
}
const issuedDate = new Date(produto.issued[0].year, produto.issued[0].month - 1, produto.issued[0].day || 1);
produto.issuedDate = issuedDate;
const issuedYear = produto.issued[0].year;
produto.issuedYear = issuedYear;
});
// Return publications sorted by the new 'issuedDate' field
return produtos.sort((a, b) => b.issuedDate - a.issuedDate);
});
/*******************************************************
* Return is the last instruction to be evaluated {{{2 *
*******************************************************/
// If needed, return an object configuration
return {
htmlTemplateEngine: "njk",
//markdownTemplateEngine: "njk",
dir: {
templateFormats: ["html", "liquid", "njk"],
input: 'src',
output: '_site',
includes: '_includes'
}
}
};
// vim: shiftwidth=2 tabstop=2 expandtab foldmethod=indent
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
*.qgz filter=lfs diff=lfs merge=lfs -text
*.pdf filter=lfs diff=lfs merge=lfs -text
*.eps filter=lfs diff=lfs merge=lfs -text
src/assets/media filter=lfs diff=lfs merge=lfs -text
src/assets/fonts filter=lfs diff=lfs merge=lfs -text
26 changes: 13 additions & 13 deletions .github/workflows/jekyll.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Sample workflow for building and deploying a Jekyll site to GitHub Pages
name: Deploy Jekyll with GitHub Pages dependencies preinstalled
name: Deploy Eleventy with GitHub Pages dependencies preinstalled

on:
# Runs on pushes targeting the default branch
Expand All @@ -25,22 +24,23 @@ concurrency:
jobs:
# Build job
build:
runs-on: ubuntu-latest
runs-on: macos-13
steps:
- name: Install pandoc
run : |
brew update
brew install pandoc pandoc-crossref jez/formulae/pandoc-sidenote
- name: Checkout
uses: actions/checkout@v4
with:
submodules: 'recursive'
lfs: true
- name: Setup Pages
uses: actions/configure-pages@v3
- name: Build with Jekyll
uses: actions/jekyll-build-pages@v1
with:
source: ./
destination: ./_site
lfs: "true"
- name: Build eleventy with npm
run : |
npm install
npm run build
- name: Upload artifact
uses: actions/upload-pages-artifact@v1
uses: actions/upload-pages-artifact@v3

# Deployment job
deploy:
Expand All @@ -53,4 +53,4 @@ jobs:
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
uses: actions/deploy-pages@v4
Loading

0 comments on commit 6bdb20d

Please sign in to comment.