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

Allow home page to be easily authored in markdown #720

Closed
bguiz opened this issue Dec 15, 2014 · 16 comments
Closed

Allow home page to be easily authored in markdown #720

bguiz opened this issue Dec 15, 2014 · 16 comments

Comments

@bguiz
Copy link

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
Copy link

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
Copy link

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
Copy link

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

@parasquid
Copy link

Looks like work has already been done here: #247

@chibicode
Copy link

👍

@chibicode
Copy link

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
Copy link

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
Copy link
Contributor

I'm going to try to fix this.

@bep
Copy link
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
Copy link
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
Copy link
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
Copy link
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
Copy link
Member

bep commented Jul 21, 2016

Will be handled in #2297.

@bep bep closed this as completed Jul 21, 2016
@kbhutiya
Copy link

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

@bep
Copy link
Member

bep commented Apr 17, 2018

is it solved yet?

yes.

@github-actions
Copy link

github-actions bot commented Mar 5, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

9 participants