Discussion:
[hakyll] Accessing an Identifier's body inside a MonadMetaData context
b***@gmail.com
2015-09-14 14:04:44 UTC
Permalink
I'd like to create a structure from the entire body of an identifier,
similar to buildTags and buildCategories, but there does not appear to be a
function to available to access the body of an identifier.

Here is buildTags:

buildTags :: MonadMetadata m => Pattern -> (String -> Identifier) -> m TagsbuildTags = buildTagsWith getTags


The important part here is getTags:

-- | Obtain tags from a page in the default way: parse them from the @tags@-- metadata field.getTags :: MonadMetadata m => Identifier -> m [String]getTags identifier = do metadata <- getMetadata identifier return $ maybe [] (map trim . splitAll ",") $ M.lookup "tags" metadata


Inside the MonadMetadata monad, we have access to metadata only. We can
cast a Pattern to a list of Identifiers with getMatches, but that's it.

Fetching an identifier's body is only possible in the Compiler context:

-- | Get the body of the underlying resourcegetResourceBody :: Compiler (Item String)getResourceBody = getResourceWith resourceBody



I want to be able to fetch the resource body, process it, and then return a
data structure like buildTags and buildCategories, which I can then pass
around:

*tags *<- buildTags "content/*/*" (fromCapture "tags/*")

categories <- buildCategories "content/*/*" (fromCapture "categories/*")

-- Elsewhere...

tagsRules *tags *$ \tag pattern -> do
let title = "Content tagged with " ++ tag
*(snip)*

Does anyone know if I can do this without having to add this functionality
to the MonadMetadata monad?

Kind Regards,
Beerend Lauwers
--
You received this message because you are subscribed to the Google Groups "hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hakyll+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Jasper Van der Jeugt
2015-09-14 16:15:49 UTC
Permalink
This is intentionally disallowed since it sort of interferes with
predicting what will need to be rebuild. What is it that you want to
achieve?

Peace,
Jasper
Post by b***@gmail.com
I'd like to create a structure from the entire body of an identifier,
similar to buildTags and buildCategories, but there does not appear to be a
function to available to access the body of an identifier.
buildTags :: MonadMetadata m => Pattern -> (String -> Identifier) -> m Tags
buildTags = buildTagsWith getTags
-- metadata field.
getTags :: MonadMetadata m => Identifier -> m [String]
getTags identifier = do
metadata <- getMetadata identifier
return $ maybe [] (map trim . splitAll ",") $ M.lookup "tags" metadata
Inside the MonadMetadata monad, we have access to metadata only. We can cast
a Pattern to a list of Identifiers with getMatches, but that's it.
-- | Get the body of the underlying resource
getResourceBody :: Compiler (Item String)
getResourceBody = getResourceWith resourceBody
I want to be able to fetch the resource body, process it, and then return a
data structure like buildTags and buildCategories, which I can then pass
tags <- buildTags "content/*/*" (fromCapture "tags/*")
categories <- buildCategories "content/*/*" (fromCapture "categories/*")
-- Elsewhere...
tagsRules tags $ \tag pattern -> do
let title = "Content tagged with " ++ tag
(snip)
Does anyone know if I can do this without having to add this functionality
to the MonadMetadata monad?
Kind Regards,
Beerend Lauwers
--
You received this message because you are subscribed to the Google Groups "hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hakyll+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
b***@gmail.com
2015-09-15 10:02:51 UTC
Permalink
Hi Jasper,

I want to load a bunch of translations from file and inject them into a
Context.

Let's assume a translation file looks like this:

---
language: en
---
translationForA: "some text"
translationForB: "some other text"

I'd like to read this file and convert each line to a context field, for
example constField "translationForA" "some text". I can then use the
context system for compile-time (well, site build-time) checking if a
translation is missing, as well as override a translation for specific
files and folders by overriding the context.

In site.hs, I'd probably just iterate over a list of languages (someone has
done this before
here: https://github.com/yogsototh/yblog/blob/master/site.hs ), matching on
(fromCapture "translations/*" lang), which reads all the files and collects
them in a list, which is then converted to a Context String.

Kind Regards,
Beerend Lauwers
Post by Jasper Van der Jeugt
This is intentionally disallowed since it sort of interferes with
predicting what will need to be rebuild. What is it that you want to
achieve?
Peace,
Jasper
Post by b***@gmail.com
I'd like to create a structure from the entire body of an identifier,
similar to buildTags and buildCategories, but there does not appear to
be a
Post by b***@gmail.com
function to available to access the body of an identifier.
buildTags :: MonadMetadata m => Pattern -> (String -> Identifier) -> m
Tags
Post by b***@gmail.com
buildTags = buildTagsWith getTags
-- | Obtain tags from a page in the default way: parse them from the
@tags@
Post by b***@gmail.com
-- metadata field.
getTags :: MonadMetadata m => Identifier -> m [String]
getTags identifier = do
metadata <- getMetadata identifier
return $ maybe [] (map trim . splitAll ",") $ M.lookup "tags"
metadata
Post by b***@gmail.com
Inside the MonadMetadata monad, we have access to metadata only. We can
cast
Post by b***@gmail.com
a Pattern to a list of Identifiers with getMatches, but that's it.
-- | Get the body of the underlying resource
getResourceBody :: Compiler (Item String)
getResourceBody = getResourceWith resourceBody
I want to be able to fetch the resource body, process it, and then
return a
Post by b***@gmail.com
data structure like buildTags and buildCategories, which I can then pass
tags <- buildTags "content/*/*" (fromCapture "tags/*")
categories <- buildCategories "content/*/*" (fromCapture "categories/*")
-- Elsewhere...
tagsRules tags $ \tag pattern -> do
let title = "Content tagged with " ++ tag
(snip)
Does anyone know if I can do this without having to add this
functionality
Post by b***@gmail.com
to the MonadMetadata monad?
Kind Regards,
Beerend Lauwers
--
You received this message because you are subscribed to the Google
Groups
Post by b***@gmail.com
"hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send
an
Post by b***@gmail.com
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hakyll+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
b***@gmail.com
2015-10-06 19:57:48 UTC
Permalink
I have a few concepts available
here: https://github.com/beerendlauwers/hakyll-extra
Post by b***@gmail.com
Hi Jasper,
I want to load a bunch of translations from file and inject them into a
Context.
---
language: en
---
translationForA: "some text"
translationForB: "some other text"
I'd like to read this file and convert each line to a context field, for
example constField "translationForA" "some text". I can then use the
context system for compile-time (well, site build-time) checking if a
translation is missing, as well as override a translation for specific
files and folders by overriding the context.
In site.hs, I'd probably just iterate over a list of languages (someone
https://github.com/yogsototh/yblog/blob/master/site.hs ), matching on
(fromCapture "translations/*" lang), which reads all the files and collects
them in a list, which is then converted to a Context String.
Kind Regards,
Beerend Lauwers
Post by Jasper Van der Jeugt
This is intentionally disallowed since it sort of interferes with
predicting what will need to be rebuild. What is it that you want to
achieve?
Peace,
Jasper
Post by b***@gmail.com
I'd like to create a structure from the entire body of an identifier,
similar to buildTags and buildCategories, but there does not appear to
be a
Post by b***@gmail.com
function to available to access the body of an identifier.
buildTags :: MonadMetadata m => Pattern -> (String -> Identifier) -> m
Tags
Post by b***@gmail.com
buildTags = buildTagsWith getTags
-- | Obtain tags from a page in the default way: parse them from the
@tags@
Post by b***@gmail.com
-- metadata field.
getTags :: MonadMetadata m => Identifier -> m [String]
getTags identifier = do
metadata <- getMetadata identifier
return $ maybe [] (map trim . splitAll ",") $ M.lookup "tags"
metadata
Post by b***@gmail.com
Inside the MonadMetadata monad, we have access to metadata only. We can
cast
Post by b***@gmail.com
a Pattern to a list of Identifiers with getMatches, but that's it.
-- | Get the body of the underlying resource
getResourceBody :: Compiler (Item String)
getResourceBody = getResourceWith resourceBody
I want to be able to fetch the resource body, process it, and then
return a
Post by b***@gmail.com
data structure like buildTags and buildCategories, which I can then
pass
Post by b***@gmail.com
tags <- buildTags "content/*/*" (fromCapture "tags/*")
categories <- buildCategories "content/*/*" (fromCapture
"categories/*")
Post by b***@gmail.com
-- Elsewhere...
tagsRules tags $ \tag pattern -> do
let title = "Content tagged with " ++ tag
(snip)
Does anyone know if I can do this without having to add this
functionality
Post by b***@gmail.com
to the MonadMetadata monad?
Kind Regards,
Beerend Lauwers
--
You received this message because you are subscribed to the Google
Groups
Post by b***@gmail.com
"hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send
an
Post by b***@gmail.com
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "hakyll" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hakyll+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...