Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

org-mode metadata not recognized #700

Open
HaoZeke opened this issue Apr 4, 2019 · 12 comments
Open

org-mode metadata not recognized #700

HaoZeke opened this issue Apr 4, 2019 · 12 comments

Comments

@HaoZeke
Copy link
Contributor

HaoZeke commented Apr 4, 2019

Hi. I noticed that even though pandoc correctly recognizes the following as metadata:

#+foo: something
#+AUTHOR: Someone
#+DATE: 10-09-2019

hakyll does not, instead it requires yaml metadata which renders the org-mode files to be quite meaningless... I believe this is because hakyll uses its own metadata-reader. Since pandoc now has better support, might it be used for all metadata?

@HaoZeke HaoZeke changed the title OrgMode metadata org-mode metadata not recognized Apr 4, 2019
@nasyxx
Copy link
Contributor

nasyxx commented Apr 7, 2019

Hi, I guess you may like a custom compiler like this:

fromOrgCompiler :: Item String -> Compiler (Item String)
fromOrgCompiler = pure . fmap (\s -> (metadatasToStr . orgMetadatas) s ++ s)

orgMetadatas :: String -> [String]
orgMetadatas = map (format . lower . clean) . takeWhile (/= "") . lines
  where
    clean = concat . splitOn ">" . concat . splitOn "#+" . concat . splitOn "<"
    lower s = (map toLower . takeWhile (/= ':')) s ++ dropWhile (/= ':') s

    -- | Custom format every metadata.
    format xs@('d' : 'a' : 't' : 'e' : _) = take 16 xs  -- drop weekday str. 2018-05-03 Thu -> 2018-05-03
    format a                              = a

metadatasToStr :: [String] -> String
metadatasToStr = ("----------\n" ++) . (++ "----------\n") . unlines

It can generate simple metadata from org format.

----------
title: About
date: 2018-05-03
author: Nasy
tags: about
categories: About
summary: About this blog and nasy, 关于此 blog 和 nasy.
comment: message board
ctitle: Message Board
href: about
----------
#+TITLE: About
#+DATE: <2018-05-03 Thu>
#+AUTHOR: Nasy
#+TAGS: about
#+CATEGORIES: About
#+SUMMARY: About this blog and nasy, 关于此 blog 和 nasy.
#+COMMENT: message board
#+CTITLE: Message Board
#+HREF: about

To use it, just: compile $ getResourceString >>= fromOrgCompiler >>= renderPandoc >>= ...

If you need tags, you may first generate temp org files to _temp/xxx:

match "posts/*.org" $ do
    route $ customRoute (\i -> ".." </> "_temp" </> toFilePath i)
    compile $ getResourceString >>= fromOrgCompiler

then

tags <- buildTags "_temp/posts/*.org" (fromCapture "tags/*.html")

@HaoZeke
Copy link
Contributor Author

HaoZeke commented Apr 8, 2019

Unfortunately, it does not exactly compile to the right output..
image
I believe it is because the metadata is only parsed once, before the rest of the rules are run...

@nasyxx
Copy link
Contributor

nasyxx commented Apr 8, 2019

I believe it is because the metadata is only parsed once, before the rest of the rules are run...

Indeed, you need to run site build twice. In addition to this, you may also need to modify customRoute.

I am modifying my blog these days, which is using this method. When I finish it, I guess, it can give you an example.

BTW, in my present blog, I use Python to generate org files with metadata first, and then site build. If you need it, you can take a look.
https://github.com/nasyxx/nasyxx.github.io/blob/dev/add_header.py

My method above just approaches this process with Haskell.

@nasyxx
Copy link
Contributor

nasyxx commented Apr 29, 2019

@HaoZeke
Hello, I have finished it, generate the metadata from org files.

See the example here:

https://github.com/nasyxx/NasyMoe/

L244-L258 The fromOrgCompiler

L90-L93 Add metadata to org files and copy them to _temp

You need to stack exec site rebuild twice. The first time to generate org files with metadata to _temp, and the second time build website from _temp.

@HaoZeke
Copy link
Contributor Author

HaoZeke commented Apr 29, 2019 via email

@jaspervdj
Copy link
Owner

Yes, agree that Hakyll should really use Pandoc's metadata parser if it's not in standard YAML format and make it available. The problem is that Hakyll assumes it can read the metadata before actually reading the file content (as an optimization), so this might make it a bit tricky to implement.

@tobiasBora
Copy link
Contributor

Any news on this? I was planning to use hakyll mostly to deal with Pandoc + org mode, and I'm quite surprised by that issue.

@karlicoss
Copy link

I'm not using Hakyll these days, but in the past I've hacked around this for my blog by messing with Metadata, in case it might help

https://github.com/karlicoss/beepb00p/blob/c522970bd8b1cfb6ffb3c8245bdcb57243a87570/hakyll/Org.hs#L36-L38
https://github.com/karlicoss/beepb00p/blob/a0bdb8fe5c6d965f21a7afd28cc27be55a838b4b/hakyll/site.hs#L340

@apraga
Copy link

apraga commented Sep 25, 2022

Hi, is this feature still doable in 2021 ? Thanks

@Minoru
Copy link
Collaborator

Minoru commented Oct 2, 2022

@apraga No-one seem to work on it at the moment, so feel free to try. Also, the workaround provided above might work for you, have you tried that?

@apraga
Copy link

apraga commented Oct 2, 2022

@Minoru At the second try, I managed to make the workaround works after a slight modification :

cleanRouteFromTemp :: Routes
cleanRouteFromTemp = customRoute createIndexRoute
  where
    createIndexRoute ident =
        (joinPath . tail . splitDirectories . takeDirectory) p
        </> takeFileName p -<.> ".html"
        where p = toFilePath ident

For tackling the issue properly, it looks like my skills are not enough :(

@jwiegley
Copy link

There is also this solution here, which does not require running the site build twice: #780

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants