Allow home page to be easily authored in markdown #720

Closed
bguiz opened this Issue Dec 15, 2014 · 15 comments

Comments

Projects
None yet
9 participants
@bguiz

bguiz commented Dec 15, 2014

Presently, it looks like the only way to put content in the home page on a hugo site with a theme is to override the theme, by creating a file /layouts/index.html, where the contents of the home page must be inserted manually using HTML. The {{ partial "foo.html" . }} syntax can only be used to include partials which also must be HTML, not markdown.

The only way I can think of working around this is to have layouts/index.html such that it ierates over all pages, and simply filters them based on the presence of a parameter, like so:

{{ range .Data.Pages }}
    {{ if isset .Params "homeContent" }}
        {{ .Content }}
    {{ end }}
{{ end }}

However, this seems like a rather roundabout, and inefficient, way of going about things. Is there a better way?

@parasquid

This comment has been minimized.

Show comment
Hide comment
@parasquid

parasquid Dec 17, 2014

I'm not sure if it's been discussed before, but I wonder if the partial command can start distinguishing the file content based on the file extension? That means

{{ partial "foo.md" }}

will then run the the file through a markdown parser, then return the cooked output back.

Again, I really don't know if there's any technical limitations to this approach (other than there's just nobody working at it at the moment)

I'm not sure if it's been discussed before, but I wonder if the partial command can start distinguishing the file content based on the file extension? That means

{{ partial "foo.md" }}

will then run the the file through a markdown parser, then return the cooked output back.

Again, I really don't know if there's any technical limitations to this approach (other than there's just nobody working at it at the moment)

@parasquid

This comment has been minimized.

Show comment
Hide comment
@parasquid

parasquid Dec 17, 2014

Ah, I've just been reading http://gohugo.io/templates/partials/ and I feel that the intention behind partials is to d one thing well: allow the ability to include repeated layout sections in template files (e.g. headers and footers). They're not designed for including content.

Maybe the better approach would be a new command called include that does include content, but from a specific folder like content/_common or content/_includes (the _ can be prefixed to tell hugo that this folder only contains files that are included and cannot stand by itself)

Ah, I've just been reading http://gohugo.io/templates/partials/ and I feel that the intention behind partials is to d one thing well: allow the ability to include repeated layout sections in template files (e.g. headers and footers). They're not designed for including content.

Maybe the better approach would be a new command called include that does include content, but from a specific folder like content/_common or content/_includes (the _ can be prefixed to tell hugo that this folder only contains files that are included and cannot stand by itself)

@parasquid

This comment has been minimized.

Show comment
Hide comment
@parasquid

parasquid Dec 17, 2014

Referencing the related community discussion here: http://discuss.gohugo.io/t/include-md-files/438

Referencing the related community discussion here: http://discuss.gohugo.io/t/include-md-files/438

@bep bep added Enhancement and removed Enhancement labels Dec 20, 2014

@parasquid

This comment has been minimized.

Show comment
Hide comment
@parasquid

parasquid Dec 21, 2014

Looks like work has already been done here: #247

Looks like work has already been done here: #247

@chibicode

This comment has been minimized.

Show comment
Hide comment

👍

@chibicode

This comment has been minimized.

Show comment
Hide comment
@chibicode

chibicode Jan 16, 2015

I tried using markdownify filter (which was added here: #652) but this doesn't work as the filter takes a string and not template.Html...

{{ partial "home.md" . | markdownify }}

I tried using markdownify filter (which was added here: #652) but this doesn't work as the filter takes a string and not template.Html...

{{ partial "home.md" . | markdownify }}
@hickford

This comment has been minimized.

Show comment
Hide comment
@hickford

hickford May 4, 2015

Hi. My site will only have one page, and I'd like to write it in Markdown. Can you help? I still want to use Hugo because of the csv dynamic content feature.

https://stackoverflow.com/questions/30030631/how-to-build-single-page-site-from-markdown

hickford commented May 4, 2015

Hi. My site will only have one page, and I'd like to write it in Markdown. Can you help? I still want to use Hugo because of the csv dynamic content feature.

https://stackoverflow.com/questions/30030631/how-to-build-single-page-site-from-markdown

@scottcwilson

This comment has been minimized.

Show comment
Hide comment
@scottcwilson

scottcwilson Jul 22, 2015

Contributor

I'm going to try to fix this.

Contributor

scottcwilson commented Jul 22, 2015

I'm going to try to fix this.

@bep

This comment has been minimized.

Show comment
Hide comment
@bep

bep Jul 22, 2015

Member

@scottcwilson talk to @spf13 -- he had a solution in place for this, that we had to roll back cause it had some side effects.

Member

bep commented Jul 22, 2015

@scottcwilson talk to @spf13 -- he had a solution in place for this, that we had to roll back cause it had some side effects.

@spf13

This comment has been minimized.

Show comment
Hide comment
@spf13

spf13 Jul 23, 2015

Contributor

So my initial solution was to add in a page handler to the homepage rendering function so it could handle a node (as it does now) or a page whose content was located in index.md. This proved problematic with pagination and overall quite a bit messier than I hoped.

A better approach would be to add support for nodes to have a content field and support nodes having content. We could actually do a lot of really neat things once that feature is in place with some of the automatically created urls (like taxonomy index pages) but before getting too far ahead I'd focus on just the home page (but think about how it would affect other places)..

Some things that need to happen:

  1. We need a mechanism and pattern to map content files to nodes. I think this is easy for the homepage just call it content/index.md, but the mapping functionality should be generic enough to be able to work for other nodes as well.
  2. Make sure that the nodes don't appear in the Site.Pages slice. (I'm not 100% sure on this)
  3. Check for any other conflicts.
  4. Add documentation and tests.

The tests I already wrote for the code I submitted should still work, we just needed a better implementation.

You can find my imperfect implementation at https://github.com/spf13/hugo/commits/spf13-content-homepage

Contributor

spf13 commented Jul 23, 2015

So my initial solution was to add in a page handler to the homepage rendering function so it could handle a node (as it does now) or a page whose content was located in index.md. This proved problematic with pagination and overall quite a bit messier than I hoped.

A better approach would be to add support for nodes to have a content field and support nodes having content. We could actually do a lot of really neat things once that feature is in place with some of the automatically created urls (like taxonomy index pages) but before getting too far ahead I'd focus on just the home page (but think about how it would affect other places)..

Some things that need to happen:

  1. We need a mechanism and pattern to map content files to nodes. I think this is easy for the homepage just call it content/index.md, but the mapping functionality should be generic enough to be able to work for other nodes as well.
  2. Make sure that the nodes don't appear in the Site.Pages slice. (I'm not 100% sure on this)
  3. Check for any other conflicts.
  4. Add documentation and tests.

The tests I already wrote for the code I submitted should still work, we just needed a better implementation.

You can find my imperfect implementation at https://github.com/spf13/hugo/commits/spf13-content-homepage

@bep

This comment has been minimized.

Show comment
Hide comment
@bep

bep Jul 26, 2015

Member

Also see #1051 -- if a Node has content it should also have frontmatter with proper title and params etc.

Member

bep commented Jul 26, 2015

Also see #1051 -- if a Node has content it should also have frontmatter with proper title and params etc.

@dimo414

This comment has been minimized.

Show comment
Hide comment
@dimo414

dimo414 Aug 10, 2015

Contributor

A general solution for nodes to contain content would be a really nice improvement! It might make sense to provide a {{ .Site.Nodes }} variable or similar at the same time, so #1303 can be addressed.

Contributor

dimo414 commented Aug 10, 2015

A general solution for nodes to contain content would be a really nice improvement! It might make sense to provide a {{ .Site.Nodes }} variable or similar at the same time, so #1303 can be addressed.

@bep

This comment has been minimized.

Show comment
Hide comment
@bep

bep Jul 21, 2016

Member

Will be handled in #2297.

Member

bep commented Jul 21, 2016

Will be handled in #2297.

@bep bep closed this Jul 21, 2016

@kbhutiya

This comment has been minimized.

Show comment
Hide comment
@kbhutiya

kbhutiya Apr 17, 2018

i know this thread is old,but i just happened to have the same issue..is it solved yet?

i know this thread is old,but i just happened to have the same issue..is it solved yet?

@bep

This comment has been minimized.

Show comment
Hide comment
@bep

bep Apr 17, 2018

Member

is it solved yet?

yes.

Member

bep commented Apr 17, 2018

is it solved yet?

yes.

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