The issues with Dynamic Routing in Abell #111
Replies: 5 comments 1 reply
-
Solution 1A const fs = require("fs");
const createPage = require("abell/createPage");
const generator = {
"./index.html": createPage("./index.abell"),
"./[path]/index.html": () => {
fs.readdirSync("./content");
}
};
module.exports = generator; Note: Example not complete. Not sure how to handle fs.readdirSync part CodeSandbox - https://codesandbox.io/s/dynamic-pages-brainstorm-n1kcv?file=/generator.js |
Beta Was this translation helpful? Give feedback.
-
Solution 2Similar to solution 1. const abell = require('abell');
abell.createPage({
template: './theme/index.abell',
out: './dist/index.html'
})
for (const contentName of ['hello-world', 'second-blog']) {
abell.createPage({
template: './theme/[path]/index.abell',
context: {
contentPath: `./content/${contentName}/index.md`
},
out: `./dist/${contentName}/index.html`
})
} |
Beta Was this translation helpful? Give feedback.
-
Solution 3Similar idea as above, different syntax - const fs = require('fs');
const abell = require('abell');
abell.generate([
{
template: './src/index.abell',
out: './dist/index.html'
},
...fs.readdirSync('./content/').map((contentDirectory) => ({
template: './src/[path]/index.abell',
context: {
contentDirectory: contentDirectory // 'hello-world'
},
out: `./dist/${contentDirectory}/index.html`
}))
]) In |
Beta Was this translation helpful? Give feedback.
-
Resolved it in v1. Draft - https://github.com/abelljs/abell/releases/tag/abell-v1.0.0-alpha.37 |
Beta Was this translation helpful? Give feedback.
-
Resolved in v1 using |
Beta Was this translation helpful? Give feedback.
-
Currently, there is a lot of abstraction in dynamic routing. We loop over
content
directory, read the names of the folders inside and pass it inAbell.meta.$path
intheme/[path]/index.abell
. You can check it out in https://github.com/abelljs/abell-starter-minimaHowever, this is too much of abstraction and something that we want to avoid in Abell going forward.
Problems with Current Dynamic Routing
[path]
,content
). In some cases it is fine but ideally, we should give helper functions to the user and the user should be one to decide how he wants to loop over a certain directory or what data they want to read.)This is one major issue that stops us from releasing v1.0.0 as the changes are going to affect the important part of Abell.
Goals
.abell
file should still work!Additional Information
How different Static-Site-Generators handle this-
Eleventy
Eleventy allows you to define layout in frontmatter of the content and then drops a content variable in that particular layout with the content of the markdown.
https://www.11ty.dev/docs/layouts/
This issue needs some brainstorming about the possible ways to move forward with dynamic routing.
Beta Was this translation helpful? Give feedback.
All reactions