Blogs and post dates

130 views
Skip to first unread message

Conal Elliott

unread,
Jul 9, 2011, 2:23:15 PM7/9/11
to hak...@googlegroups.com
I'm switching my blog from WordPress to Hakyll, and I'm wondering how to handle sorting of posts. I gather that a popular convention is to prefix the post's file name with a date (e.g., "2011-07-09-my-post.md"). I have a couple of misgivings about adopting this practice:

* When I begin a post, I don't know when I'll publish it, and I'd like the order to by appearance. I guess I could begin without a date and then rename the file when I'm ready to publish.
* Sometimes I publish more than one post in a given day, and I still want them (reverse-)sorted by publication date & time.

Have others mulled over these issues?

Thanks,   - Conal

Jasper Van der Jeugt

unread,
Jul 9, 2011, 2:33:31 PM7/9/11
to hak...@googlegroups.com
> * When I begin a post, I don't know when I'll publish it, and I'd like the
> order to by appearance. I guess I could begin without a date and then rename
> the file when I'm ready to publish.

I remember someone who had a `/drafts` folder in addition to a
`/posts` folder. I can't find the code, but it's pretty easy to
implement: posts in the drafts folder are unordered and have no
listing page (since they are just used for local previewing).

> * Sometimes I publish more than one post in a given day, and I still want
> them (reverse-)sorted by publication date & time.

Ok, so this is a little harder. I figure the way to go here is to use
an extended version of the naming format: e.g.,
"2011-07-09-15-my-post.md" for a post published at 3AM. This should
just work, except for (and this is where it gets a little harder) when
you want to display the post time on your site. In that case, you will
have to write your own version of `renderDateField` [1] (have a look
at the source code).

[1]: http://hackage.haskell.org/packages/archive/hakyll/3.2.0.3/doc/html/Hakyll-Web-Page-Metadata.html#v:renderDateField

Cheers,
Jasper

Nicolas Wu

unread,
Jul 9, 2011, 6:26:51 PM7/9/11
to hak...@googlegroups.com
On 9 July 2011 19:33, Jasper Van der Jeugt <m...@jaspervdj.be> wrote:
>> * When I begin a post, I don't know when I'll publish it, and I'd like the
>> order to by appearance. I guess I could begin without a date and then rename
>> the file when I'm ready to publish.
>
> I remember someone who had a `/drafts` folder in addition to a
> `/posts` folder. I can't find the code, but it's pretty easy to
> implement: posts in the drafts folder are unordered and have no
> listing page (since they are just used for local previewing).

That someone is probably me :-)

I was hoping to get round to posting my Hakyll code as a blog post at
some point, but until then, here's the gist of what I have. I tend to
run my hakyll site with "preview" as argument, which basically changes
my post paths:

main :: IO ()
main = liftIO getArgs >>= \args -> hakyll $ do
let postPath = case "preview" `elem` args of
True -> "posts/**.lhs"
False -> (predicate (\ident -> matches "posts/**.lhs" ident &&
not (matches ("posts/draft/**") ident)))

Later on, I publish the posts with the following code:

match "posts.html" $ route idRoute
create "posts.html" $ constA mempty
>>> arr (setField "title" "All posts")
>>> requireAllA postPath addPostList
>>> (requireA "tags" (setFieldA "taglist"
(renderTagList tagIdentifier :: Compiler (Tags String) String)))
>>> applyTemplateCompiler "templates/posts.html"
>>> decorate
match postPath $ do
route $ setExtension ".html"
compile $ pageCompilerWith myHakyllParserState myHakyllWriterOptions
>>> arr (renderDateField "date" "%e %B %Y" "Date unknown")
>>> arr (copyBodyToField "description")
>>> renderTagsField "taglist" tagIdentifier
>>> applyTemplateCompiler "templates/post.html"
>>> decorate

That might not be enough to go on. If not, let me know and I'd be happy to help.

>> * Sometimes I publish more than one post in a given day, and I still want
>> them (reverse-)sorted by publication date & time.
>
> Ok, so this is a little harder. I figure the way to go here is to use
> an extended version of the naming format: e.g.,
> "2011-07-09-15-my-post.md" for a post published at 3AM.

I think you mean 3pm? I'm wondering if the "right" thing to do is to
publish the whole time? For example 2011-07-09-232500. I'd be tempted
to put colons in that time, but that would make your files Windows
incompatible.

Donald Ephraim Curtis

unread,
Jul 12, 2011, 5:45:50 PM7/12/11
to hak...@googlegroups.com
I use the format: YYYY-mm-dd-HHMM-Title.md

Here is a link to my file. I don't have time to figure out what exactly I did.


there are lots of processing I do on each post, but the main you want to consider is the `routing` and `compile` for "brain/*.md".

`cleanDate` is what removes the date prefix form my file.
and
`addPosted` is the function that i use to replace `renderDate` which is what Jasper was talking about


I use a drafts folder, and I don't normally worry about previewing it. When I work on a post if I want to preview it, i just move it to the published folder and use my local running instance to preview.

Reply all
Reply to author
Forward
0 new messages