description metadata #265

Open
gwern opened this Issue Jul 19, 2011 · 2 comments

Comments

Projects
None yet
2 participants
Contributor

gwern commented Jul 19, 2011

(Didn't realize the Google bugtracker was closed and posted to https://code.google.com/p/gitit/issues/detail?id=121 )

Currently Gitit only supports format/categories/toc/title (http://gitit.johnmacfarlane.net/README#page-metadata). There's another obvious bit of metadata, a description, which maps onto a standard HTML tag which is apparently widely used by search engines and other tools.

So one could have a


description: Listings and reviews of Dutch cheeses
...

And using

get

Adding a new metadata field turns out to be... not as easy as I had hoped. Gitit's dependencies are taking forever to install so I can't test this now, but I think something close to this change should work to define a new metadata field and then conditionally include it in an appropriate metadata HTML tag:

diff --git a/Network/Gitit/Layout.hs b/Network/Gitit/Layout.hs
index 7073df1..78b6a7c 100644
--- a/Network/Gitit/Layout.hs
+++ b/Network/Gitit/Layout.hs
@@ -106,6 +106,7 @@ filledPageTemplate base' cfg layout htmlContents templ =
T.setAttribute "messages" (pgMessages layout) .
T.setAttribute "usecache" (useCache cfg) .
T.setAttribute "content" (renderHtmlFragment htmlContents) .

  •               setBoolAttr "descriptionExists" (pageDescription page /= "")
                setBoolAttr "wikiupload" ( uploadsAllowed cfg) $
                templ
    

diff --git a/Network/Gitit/Page.hs b/Network/Gitit/Page.hs
index e0fc274..3f89612 100644
--- a/Network/Gitit/Page.hs
+++ b/Network/Gitit/Page.hs
@@ -96,6 +96,7 @@ stringToPage conf pagename raw =
, pageLHS = defaultLHS conf
, pageTOC = tableOfContents conf
, pageTitle = pagename

  •               , pageDescription = ""
                , pageCategories  = []
                , pageText        = filter (/= '\r') rest
                , pageMeta        = ls }
    

    @@ -109,6 +110,7 @@ adjustPage ("toc", val) page' = page' {
    pageTOC = map toLower val elem ["yes","true"] }
    adjustPage ("categories", val) page' =
    page' { pageCategories = splitCategories val ++ pageCategories page' }
    +adjustPage ("description", val) page' = page' { description = val }
    adjustPage (_, _) page' = page'

    -- | Write a string (the contents of a page file) corresponding to
    diff --git a/Network/Gitit/Types.hs b/Network/Gitit/Types.hs
    index 67b70c2..d121ea6 100644
    --- a/Network/Gitit/Types.hs
    +++ b/Network/Gitit/Types.hs
    @@ -153,6 +153,7 @@ data Page = Page {
    , pageTOC :: Bool
    , pageTitle :: String
    , pageCategories :: [String]

  • , pageDescription :: String
    , pageText :: String
    , pageMeta :: [(String, String)]
    } deriving (Read, Show)
    diff --git a/data/templates/page.st b/data/templates/page.st
    index e1a1725..5e6af16 100644
    --- a/data/templates/page.st
    +++ b/data/templates/page.st
    @@ -3,6 +3,9 @@

- $if(descriptionExists)$ - - $endif$ $if(feed)$ @@ -21,7 +24,7 @@
$userbox()$ - $tabs$ - $tabs$ $content()$ $footer()$
Owner

jgm commented Jul 19, 2011

I'd have more confidence if you could certify that this worked well
after some extensive testing.

+++ gwern [Jul 19 11 15:25 ]:

(Didn't realize the Google bugtracker was closed and posted to https://code.google.com/p/gitit/issues/detail?id=121 )

Currently Gitit only supports format/categories/toc/title (http://gitit.johnmacfarlane.net/README#page-metadata). There's another obvious bit of metadata, a description, which maps onto a standard HTML tag which is apparently widely used by search engines and other tools.

So one could have a


description: Listings and reviews of Dutch cheeses
...

And using

get

Adding a new metadata field turns out to be... not as easy as I had hoped. Gitit's dependencies are taking forever to install so I can't test this now, but I think something close to this change should work to define a new metadata field and then conditionally include it in an appropriate metadata HTML tag:

diff --git a/Network/Gitit/Layout.hs b/Network/Gitit/Layout.hs
index 7073df1..78b6a7c 100644
--- a/Network/Gitit/Layout.hs
+++ b/Network/Gitit/Layout.hs
@@ -106,6 +106,7 @@ filledPageTemplate base' cfg layout htmlContents templ =
T.setAttribute "messages" (pgMessages layout) .
T.setAttribute "usecache" (useCache cfg) .
T.setAttribute "content" (renderHtmlFragment htmlContents) .

  •               setBoolAttr "descriptionExists" (pageDescription page /= "")
                setBoolAttr "wikiupload" ( uploadsAllowed cfg) $
                templ
    

diff --git a/Network/Gitit/Page.hs b/Network/Gitit/Page.hs
index e0fc274..3f89612 100644
--- a/Network/Gitit/Page.hs
+++ b/Network/Gitit/Page.hs
@@ -96,6 +96,7 @@ stringToPage conf pagename raw =
, pageLHS = defaultLHS conf
, pageTOC = tableOfContents conf
, pageTitle = pagename

  •               , pageDescription = ""
                , pageCategories  = []
                , pageText        = filter (/= '\r') rest
                , pageMeta        = ls }
    

    @@ -109,6 +110,7 @@ adjustPage ("toc", val) page' = page' {
    pageTOC = map toLower val elem ["yes","true"] }
    adjustPage ("categories", val) page' =
    page' { pageCategories = splitCategories val ++ pageCategories page' }
    +adjustPage ("description", val) page' = page' { description = val }
    adjustPage (_, _) page' = page'

    -- | Write a string (the contents of a page file) corresponding to
    diff --git a/Network/Gitit/Types.hs b/Network/Gitit/Types.hs
    index 67b70c2..d121ea6 100644
    --- a/Network/Gitit/Types.hs
    +++ b/Network/Gitit/Types.hs
    @@ -153,6 +153,7 @@ data Page = Page {
    , pageTOC :: Bool
    , pageTitle :: String
    , pageCategories :: [String]

  • , pageDescription :: String
    , pageText :: String
    , pageMeta :: [(String, String)]
    } deriving (Read, Show)
    diff --git a/data/templates/page.st b/data/templates/page.st
    index e1a1725..5e6af16 100644
    --- a/data/templates/page.st
    +++ b/data/templates/page.st
    @@ -3,6 +3,9 @@

- $if(descriptionExists)$ - - $endif$ $if(feed)$ @@ -21,7 +24,7 @@
$userbox()$ - $tabs$ - $tabs$ $content()$ $footer()$
Contributor

gwern commented Jul 19, 2011

Testing? This doesn't even compile. (Apparently the suggestively named 'page' variable is actually a PageLayout, whatever that is, with no obvious route to the Page or its metadata.)

Or did you mean the element itself and the description: field? It works fine in Hakyll (recently edited to imitate Gitit's trailing '...'). You can see it on gwern.net - validates and everything: http://validator.w3.org/check?uri=http%3A%2F%2Fwww.gwern.net&charset=%28detect+automatically%29&doctype=Inline&group=0

@gwern gwern closed this Jul 19, 2011

@gwern gwern reopened this Jul 19, 2011

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