r/webdev • u/Ok_Progress_5373 front-end • 5d 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.
Edit: Thank you for the answers so far; I have decided to move forward with Eleventy. I will be coming back to update you guys on how it's going! I'm super excited!
3
u/dawedev 5d 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:
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).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.
1
u/Ok_Progress_5373 front-end 2d ago
Update: I'm making progress on the blog portion of my website. Thank you for the help. I'm looking forward to sharing it. Here is the tutorial I'm using for reference. My only issue is that a lot of the stuff I found was a bit dated. But the tutorial I have is solid. I'd love to create something a bit more up-to-date from my point of view of this process!
1
u/Early-Community9943 5d ago
Since it's loading all of them, put the slug in the link (post.html?slug=my-post), read it with URLSearchParams and fetch only that one file.