sintaxi / harp

Static Web Server/Generator/Bundler
http://harpjs.com
5k stars 343 forks source link

Best way to deal with blogs. #520

Closed IngwiePhoenix closed 8 years ago

IngwiePhoenix commented 8 years ago

I wonder what the best practice is for making blogs with Harp.

Do I...

What's the right way to go?

kennethormandy commented 8 years ago

Hey, Harp works great for blogs, but we intentionally avoided doing anything blog-specific, since Harp isn’t exclusively for blogs. Harp doesn’t support front matter in Markdown, but you can use the flexible metadata _data.json files for that.

I wrote an article about how I approach this, which might be helpful: Start a blog with Harp.

You can also see how we built the harpjs.com/blog, and my hb-remedy, hb-casper, and hb-simurai blogs are all open source.

IngwiePhoenix commented 8 years ago

Thanks @kennethormandy ! I'll look into these links. I'm looking forward to build many static sites with Harp - the blog being one. Others are portfolios for my projects and documentations. Gonna be really interesting. :)

I'll let you know once i read the links.

IngwiePhoenix commented 8 years ago

So all the blog does is keep a properly ordered JSON object of the blog entries - and they'll be in that very exact order? Im just worried that this may break... Especially, automating the creation of posts would be a problem... because first having to touch a markdown file, then manually go and taptaptap something into the JSON file and making sure the JSON doesn't break, then writing the article and hoping it ll goes well together seems...a bit awkward, to me.

ir-g commented 8 years ago

Yaml front matter can be more convenient. It is possible to modify a JSON file nicely through NodeJS.

On Mon, 14 Dec 2015 19:56 Ingwie Phoenix notifications@github.com wrote:

So all the blog does is keep a properly ordered JSON object of the blog entries - and they'll be in that very exact order? Im just worried that this may break... Especially, automating the creation of posts would be a problem... because first having to touch a markdown file, then manually go and taptaptap something into the JSON file and making sure the JSON doesn't break, then writing the article and hoping it ll goes well together seems...a bit awkward, to me.

— Reply to this email directly or view it on GitHub https://github.com/sintaxi/harp/issues/520#issuecomment-164541779.

cfjedimaster commented 8 years ago

If you are automating the JSON creation, then it shouldn't be a problem. If you editing the JSON by hand, then your editor should provide feedback if your JSON is bad. (Mine does.)

szutzkus commented 8 years ago

I am hitting a wall trying to get my head around the blog examples. Any help is welcome!

My data is quite usual in file _data.json:

{ "hello-world": { "title": "Hello World", "author" : "Me", "date" : "2015.12.26" } }

In index.jade, I am using a loop:

each post, slug in public.posts._data != partial("/posts/" + slug, {title:post.title, date:post.date, author:post.author, slug:slug})

My first question: where does the "slug" come from? Is it hard-coded for the "key"?

The concrete issue I have: On the index page, the content is correct and the link to the blog posts work. On the post page itself, the slug variable is "lost", so the link (to the page itself) is "undefined".

My header file (header.jade): h2: a(href="/posts/"+slug) != title em Written by !=author em on !=date

My blog post file (hello-world.jade): != slug // here is the issue: it is filled on index, but not on hello-world != partial("../_partials/header", {slug:slug})

p.lead Lorem ipsum Sunt occaecat exercitation quis voluptate tempor ..

I am looking forward for any hints.

kennethormandy commented 8 years ago

Slug isn’t hard coded, but yes it’s the key. You could call it anything:

ul
  each post, key, in public.posts_data
    li= key

So it’s not always there, it’s only there in a for or each loop. If you are trying to pass in the current page on hello-world.jade you could use current if it’s dynamic (although I’m not sure I understand the context):

//- hello-world.jade
!= partial("../_partials/header", {slug: current.source})

In regards to @IngwiePhoenix, we rely on Node for that and feel comfortable with it. We haven’t had any trouble with it, and ordering is preserved for objects in V8 / Node.js. (I am not an expert on that stuff, but there is another issue that goes into it in more depth; if there was a change, we’d ensure Harp mitigated that.) If you are really concerned about it, you can also just make your _data.json file an array.

I am going to close this issue now, hopefully that works for everyone.

szutzkus commented 8 years ago

He Kenneth, thank you very much for your fast reply. Using current.source, I am able to use this on any given post pages via the header partial. This solution works for me. [For the index page however I will need another snippet because there the source is index of course. But that is ok for me, thank you a lot.] I do not know if I am re-opening this issue again with my commen - if so I appologize for the inconvenience. Please close the issue again. Best regards, Thorsten