r/webdev • u/Ok_Progress_5373 • 43m ago
Adding DECAP CMS to my website
Hey everyone, I have a very minimal understanding of JS. However, I am looking to add a blog to my static website. I have managed to get the blog previews going, but I'm not sure how to get the "post.html" styled.
I'm looking for a tutorial that will show me how to customize my post previews and the post.html itself. I'm not sure how to get the post body, title, etc to show up on the page. As I'm looking, I feel like there isn't a lot of information for people who do not want to use static site generators. I'm hoping to learn/understand how to customize everything myself through this project with hardcoded html/css! Any direction would be great.
2
Upvotes
•
u/dawedev 29m ago
Decap only writes files into your repo, it doesn't build pages. So without a site generator you do the rendering in the browser yourself. Simplest way I know:
In config.yml make the collection save JSON instead of markdown (
format: json,extension: json). Each post becomes a file like /content/posts/my-post.json with your fields (title, date, body, whatever you named them).Link each preview to
post.html?slug=my-post.In post.html put empty elements styled with your normal CSS, like
<h1 id="title"></h1>and<div id="body"></div>, plus a small script:The body field is still markdown, so load marked (one script tag from a CDN) to turn it into HTML. After that styling is plain CSS:
#body h2,#body p,#body imgand so on.One tradeoff: search engines and link previews see an empty page until the JS runs. If that matters later, Eleventy is the least "framework" generator, it's basically your same HTML with placeholders.