New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(how) can I add a custom "renderer engine" / file type? #645
Comments
Would you upvote #117? |
@Ryuno-Ki done that. also figured out the for future reference, this is the code i came up with, parsing yaml+markdown content into html to allow for declaring "map markers" on an image; shortened to the important bits (my actual code does more calculations to make the pins i declared position/orient nicer, and obviously needs some additional css): // my_layout.11ty.js
const yaml = require('js-yaml');
module.exports = class {
data() {
return {
layout: 'page' // my main layout for most pages
};
}
render(data) {
var self = this;
var out='<div class="map">'
var map = yaml.safeLoad(data.content);
out += `<img src="${map.img}" />`;
map.pins.forEach(function(pin){
out += `<div class="pin" style="left: ${pin.x}%; top: ${pin.y}%;">${self.md(pin.text)}</div>`;
// self.md is just a filter i declared that just runs markdownIt.renderInline, to allow for nested markdown here
});
return out+'</div>';
}
} ---
# map.liquid
layout: my_layout
---
img: {{'/assets/img/map_bg.png'|url}}
pins:
- text : "[Center]({{'/universe/center'|url}}) of the universe"
x : 50
y : 50 |
Do yourself a favour and add an |
Oh, and instead of a String concatenation (which absorbs your memory in no time), you can put the parts into an Array and run a |
well it's literally the background image for a map i'm marking places on using that code, sooo don't really see any way of describing that meaningfully. why would you advise adding an empty also that tiny bit of memory isn't really an issue for me (got 32gig of that stuff, and only need it when i deploy the site, got not a single line of js actually running in a browser; also python land memory management doesn't translate to nodejs necessarily), i prefer instantly readable code :P |
Valid HTML demands the presence of an |
Enter Python! (Honestly, I hear that argument on both ends …) |
yeah no thanks, enter moonscript :P i'd never claim javascript was readable, i just said |
Oh cool! I was about to learn Lua anyway. Will take a note to look into MoonScript at a later point. Thanks! What |
interestingly, it seems like |
:D are we good here to lump this in with #117? I believe the code for this is ready-ish in the |
sounds like it yeah. and until it ships my layout hack works fine :) |
I'd like to add a custom "renderer" for a specific file type, but the only part that kinda looks related (
static get TemplateEngine::templateKeyMapToClassName
) seems verystatic
, is there any way to do this?I need files of a specific ending to have their front matter and (if any) liquid tags etc parsed and then want to supply a
function(data,content){return html}
(that then gets passed along through thecontent
of the layout engine etc), essentially just replacing the markdown/html parsing part of the chain.so just like a
.md
file gets passed through frontmatter, liquid, markdown, and layouting, i want my.something
file get passed through frontmatter, liquid, my function, and then layouting.since I will use the frontmatter, I feel I could also do this via a custom layout file maybe, though, not really understanding the
11ty.js
format, I don't know how I would actually write that and also prevent eleventy from trying to parse the content through another renderer before passing it to my layout (would just calling it.liquid
or.html
suffice, to make it essentially just pass through the contents after parsing any shortcodes/etc)?The text was updated successfully, but these errors were encountered: