blog-maker

v1.0.0
Blog generator from .md post files, highly inspired from blog.nodejs.org
blog node markdown

blog-maker -- generate blog from .md files, highly inspired by blog.nodejs.org

Description

This blog generator is highly inspired by blog.nodejs.org (meaning, I've extracted the code which make it works from https://github.com/joyent/node to make it work as a stand alone module =) )

Big props to @dshaw for giving me this idea and @isaacs for explaining me how the magic was done =)

Install

  npm install blog-maker

How to use

To generate a simple blog, you will need:

  • A folder where you insert the blog posts as .md files
  • An rss.xml template to generate the blog feed
  • An .html file to use as template for each blog post

You can find examples of this in the 'data' folder of this repo

To use it, just require the module

var blogMaker = require('blog-maker');

And then call the function returned with the following args:

  • - for example data/posts
  • - output folder
  • - for example data/blog.html
  • - for example data/rss.xml
  • [blogPath] - if you want your blog to be hosted in yourdomain.com/blog, pass 'blog' in this arg
  • [numberOfPostPerPage] - number of posts presented per page

example:

blogMaker('data/posts', 'public', 'data/blog.html', 'data/rss.xml')

You can find and example using node-static to server the blog posts in the 'example' folder, to try it, just run node example/example_run.js

A blog contributors guide template

Structure

data/posts - Folder containing all the posts

data/blog.html - blog page template (for each post)

data/rss.xml - rss feed template

Adding a new post

  1. Open data/posts folder
  2. Create a new .md file</li> <li>Add title, author, date, slug and category, e.g:</li> </ol> <ul> <li>title: Best post in the world</li> <li>author: Alice</li> <li>date: Fri Jan 12 00:45:13 UTC 2012</li> <li>slug: megapost</li> <li>category: postland</li> </ul> <ol start="4"> <li><p>Write your post (use html you want) <code><blockquote></blockquote></code> <code><code></code></code> You name it :)</p> </li> <li><p>Then you just have to run blog-maker</p> </li> </ol> <p>Note: folder hierarchy in data/posts is meaningless, you can use it for your own organization, for example, one folder for each author or for each category</p> <h2>License</h2> <p>(The MIT License)</p> <p>Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:</p> <p>The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.</p> <p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.</p> </div> </div> <div class="mt-3 rounded-2xl bg-surface pb-2 pl-4 pr-4 md:mt-0 md:w-1/4"> <div class="pt-5"> <div class="overflow-x-auto whitespace-nowrap rounded-lg border bg-background p-2 pl-5 pr-5 text-center font-code text-lg"> npm i blog-maker </div> </div> <div> <h2>Source Code</h2> <a href="https://github.com/diasdavid/blog-maker.git" class="overflow-x-auto whitespace-nowrap rounded-lg bg-background p-2 text-white no-underline"> <span class="pl-2 pr-2"> github.com/diasdavid/blog-ma... </span> </a> <h2>Homepage</h2> <a href="https://github.com/diasdavid/blog-maker" class="rounded-lg bg-background p-2 text-white no-underline"> <span class="pl-2 pr-2"> github.com/diasdavid/blog-ma... </span> </a> </div> <div> <h2>Metadata</h2> <ul class="space-y-2 pl-2"> <li class="flex items-center space-x-2"> <svg stroke="currentColor" fill="none" stroke-width="2" viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" style="--darkreader-inline-stroke: currentColor;" class="h-6 w-6" data-darkreader-inline-stroke=""><path stroke="none" d="M0 0h24v24H0z" fill="none" style="--darkreader-inline-stroke: none;" data-darkreader-inline-stroke=""></path><path d="M15 21h-9a3 3 0 0 1 -3 -3v-1h10v2a2 2 0 0 0 4 0v-14a2 2 0 1 1 2 2h-2m2 -4h-11a3 3 0 0 0 -3 3v11"></path><path d="M9 7l4 0"></path><path d="M9 11l4 0"></path></svg> <a href="https://directory.fsf.org/wiki/License:MIT" class="text-white no-underline"> <span class="rounded-lg bg-background p-1 pl-2 pr-2"> MIT </span> </a> </li> <li class="flex items-center space-x-2"> <svg class="h-6 w-6" stroke="currentColor" fill="none" stroke-width="2" viewBox="0 0 24 24" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg" style="--darkreader-inline-stroke: currentColor;" data-darkreader-inline-stroke=""><path stroke="none" d="M0 0h24v24H0z" fill="none" style="--darkreader-inline-stroke: none;" data-darkreader-inline-stroke=""></path><path d="M9 9v8.044a2 2 0 0 1 -2.996 1.734l-1.568 -.9a3 3 0 0 1 -1.436 -2.561v-6.635a3 3 0 0 1 1.436 -2.56l6 -3.667a3 3 0 0 1 3.128 0l6 3.667a3 3 0 0 1 1.436 2.561v6.634a3 3 0 0 1 -1.436 2.56l-6 3.667a3 3 0 0 1 -3.128 0"></path><path d="M17 9h-3.5a1.5 1.5 0 0 0 0 3h2a1.5 1.5 0 0 1 0 3h-3.5"></path></svg> <span class="rounded-lg bg-background p-1 pl-2 pr-2"> Whatever </span> </li> <li class="flex items-center space-x-2"> <svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 448 512" class="h-6 w-6" xmlns="http://www.w3.org/2000/svg"><path d="M224 256c70.7 0 128-57.3 128-128S294.7 0 224 0 96 57.3 96 128s57.3 128 128 128zm89.6 32h-16.7c-22.2 10.2-46.9 16-72.9 16s-50.6-5.8-72.9-16h-16.7C60.2 288 0 348.2 0 422.4V464c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48v-41.6c0-74.2-60.2-134.4-134.4-134.4z"></path></svg> <span class="rounded-lg bg-background p-1 pl-2 pr-2"> David Dias </span> </li> <li class="flex items-center space-x-2"> <svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 20 20" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" class="h-6 w-6"><path fill-rule="evenodd" d="M3 17a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM6.293 6.707a1 1 0 010-1.414l3-3a1 1 0 011.414 0l3 3a1 1 0 01-1.414 1.414L11 5.414V13a1 1 0 11-2 0V5.414L7.707 6.707a1 1 0 01-1.414 0z" clip-rule="evenodd"></path></svg> <span class="rounded-lg bg-background p-1 pl-2 pr-2"> released 4/19/2015 </span> </li> </ul> </div> <div> <h2>Downloads</h2> <style>astro-island,astro-slot,astro-static-slot{display:contents}</style><script>(()=>{var e=async t=>{await(await t())()};(self.Astro||(self.Astro={})).only=e;window.dispatchEvent(new Event("astro:only"));})();;(()=>{var b=Object.defineProperty;var f=(c,o,i)=>o in c?b(c,o,{enumerable:!0,configurable:!0,writable:!0,value:i}):c[o]=i;var l=(c,o,i)=>(f(c,typeof o!="symbol"?o+"":o,i),i);var p;{let c={0:t=>m(t),1:t=>i(t),2:t=>new RegExp(t),3:t=>new Date(t),4:t=>new Map(i(t)),5:t=>new Set(i(t)),6:t=>BigInt(t),7:t=>new URL(t),8:t=>new Uint8Array(t),9:t=>new Uint16Array(t),10:t=>new Uint32Array(t)},o=t=>{let[e,r]=t;return e in c?c[e](r):void 0},i=t=>t.map(o),m=t=>typeof t!="object"||t===null?t:Object.fromEntries(Object.entries(t).map(([e,r])=>[e,o(r)]));customElements.get("astro-island")||customElements.define("astro-island",(p=class extends HTMLElement{constructor(){super(...arguments);l(this,"Component");l(this,"hydrator");l(this,"hydrate",async()=>{var d;if(!this.hydrator||!this.isConnected)return;let e=(d=this.parentElement)==null?void 0:d.closest("astro-island[ssr]");if(e){e.addEventListener("astro:hydrate",this.hydrate,{once:!0});return}let r=this.querySelectorAll("astro-slot"),a={},h=this.querySelectorAll("template[data-astro-template]");for(let n of h){let s=n.closest(this.tagName);s!=null&&s.isSameNode(this)&&(a[n.getAttribute("data-astro-template")||"default"]=n.innerHTML,n.remove())}for(let n of r){let s=n.closest(this.tagName);s!=null&&s.isSameNode(this)&&(a[n.getAttribute("name")||"default"]=n.innerHTML)}let u;try{u=this.hasAttribute("props")?m(JSON.parse(this.getAttribute("props"))):{}}catch(n){let s=this.getAttribute("component-url")||"<unknown>",y=this.getAttribute("component-export");throw y&&(s+=` (export ${y})`),console.error(`[hydrate] Error parsing props for component ${s}`,this.getAttribute("props"),n),n}await this.hydrator(this)(this.Component,u,a,{client:this.getAttribute("client")}),this.removeAttribute("ssr"),this.dispatchEvent(new CustomEvent("astro:hydrate"))});l(this,"unmount",()=>{this.isConnected||this.dispatchEvent(new CustomEvent("astro:unmount"))})}disconnectedCallback(){document.removeEventListener("astro:after-swap",this.unmount),document.addEventListener("astro:after-swap",this.unmount,{once:!0})}connectedCallback(){if(!this.hasAttribute("await-children")||document.readyState==="interactive"||document.readyState==="complete")this.childrenConnectedCallback();else{let e=()=>{document.removeEventListener("DOMContentLoaded",e),r.disconnect(),this.childrenConnectedCallback()},r=new MutationObserver(()=>{var a;((a=this.lastChild)==null?void 0:a.nodeType)===Node.COMMENT_NODE&&this.lastChild.nodeValue==="astro:end"&&(this.lastChild.remove(),e())});r.observe(this,{childList:!0}),document.addEventListener("DOMContentLoaded",e)}}async childrenConnectedCallback(){let e=this.getAttribute("before-hydration-url");e&&await import(e),this.start()}start(){let e=JSON.parse(this.getAttribute("opts")),r=this.getAttribute("client");if(Astro[r]===void 0){window.addEventListener(`astro:${r}`,()=>this.start(),{once:!0});return}Astro[r](async()=>{let a=this.getAttribute("renderer-url"),[h,{default:u}]=await Promise.all([import(this.getAttribute("component-url")),a?import(a):()=>()=>{}]),d=this.getAttribute("component-export")||"default";if(!d.includes("."))this.Component=h[d];else{this.Component=h;for(let n of d.split("."))this.Component=this.Component[n]}return this.hydrator=u,this.hydrate},e,this)}attributeChangedCallback(){this.hydrate()}},l(p,"observedAttributes",["props"]),p))}})();</script><astro-island uid="1Ki0IR" component-url="/_astro/PackageDownloads.J8YmCCO0.js" component-export="default" renderer-url="/_astro/client.2wOxL1Aq.js" props="{"name":[0,"blog-maker"]}" ssr="" client="only" opts="{"name":"PackageDownloads","value":true}"></astro-island> <noscript> <a href="/blog-maker/downloads">Downloads Tab Here</a> </noscript> </div> <div> <h2>Maintainers</h2> <div> <a class="text-white no-underline" href="/~daviddias"> <div class="mb-2 flex items-center space-x-2"> <img class="h-11 w-11 rounded-full" alt="@daviddias" src="/~daviddias/profile.png"> <span class="rounded-lg bg-background p-1 pl-2 pr-2"> daviddias </span> <br> </div> </a> </div> </div> </div> </div> </div> </main> </div> </div> </body></html>