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

Minimalist website with homepage as content #330

Closed
falzm opened this issue Jun 13, 2014 · 33 comments
Closed

Minimalist website with homepage as content #330

falzm opened this issue Jun 13, 2014 · 33 comments

Comments

@falzm
Copy link

falzm commented Jun 13, 2014

Hi

I'd like to use Hugo for my personal website, which roughly consists of two HTML pages:

I'm actually struggling to do a simple thing, which doesn't seem to be possible to do with Hugo: write the content of the homepage (a.k.a. /index.html) as Markdown — content/index.md for instance —, among other content pages in the content/ directory. For what I understand from the documentation, the homepage has a special status, and requires a dedicated template file for display.

My problem is: I don't want the content of the homepage to be directly in the HTML template, I want it to be written as Markdown in content/ as any other page, and rendered/included in the layout/index.html template file. Is there any way to achieve this? If not, what simple workaround can you suggest so I can keep the simple structure of my website?

Cheers,

m.

@spf13
Copy link
Contributor

spf13 commented Jun 13, 2014

I'm working on exactly this use case. Hope to have something ready soon.

@falzm
Copy link
Author

falzm commented Jun 13, 2014

Great!

@RubenN
Copy link
Contributor

RubenN commented Jul 8, 2014

Exactly what i'm looking for!
Any update on this use case?

@falzm
Copy link
Author

falzm commented Jul 18, 2014

Hi @spf13, any update on this feature?

@tkschmidt
Copy link
Contributor

This feature is also interesting for me. Until now I used an own content type with just one entry, but this then breaks prev and next posts.
I don't want to have my about.html as part of a list of all my blog-posts.

@mbertschler
Copy link

@tkschmidt @falzm @RubenN I managed to come up with workaround that works good for me until there is a proper fix for this:

/content/index.md file containing url = "index.html" in the front matter
(this alone does not make it work, but it ensures that this content is not generated for into a /index/ folder in the public directory)

then add the following code to the /layouts/index.html body section

{{ range .Data.Pages }}
        {{if eq .RelPermalink "/index.html" }} {{.Content}} {{end}}
{{ end }}

because the index.md file has url set to index.html, hugo translates this into the .RelPermalink = "/index.html". With this hack only the content of the index.md file is shown on the homepage.

@spf13
Copy link
Contributor

spf13 commented Aug 25, 2014

@mbertschler That's pretty brilliant. Way to work within the system. I don't mind that solution at all.... of course it would be nice to have a proper one at some point.

@zwotzie
Copy link

zwotzie commented Dec 22, 2014

@mbertschler : in my setup with v0.12. it is not a solution. Which version do you use?

@mbertschler
Copy link

@zwotzie I am using v0.12
This is how it works great in my current website project.

Contents of layouts/_default/single.html

{{ template "partials/header.html" . }}
    {{ .Content }}
{{ template "partials/footer.html" . }}

Contents of layouts/index.html

{{ template "partials/header.html" . }}
{{ range .Data.Pages }}
    {{if eq .Type "index" }} 
        {{.Content}}
    {{end}}
{{ end }}
{{ template "partials/footer.html" . }}

Contents of content/index.md

+++
type = "index"
+++
Content in *Markdown*

I hope that helps.

@zwotzie
Copy link

zwotzie commented Dec 22, 2014

@mbertschler that works perfekt for me, except the title, which will be used from the config-file but that ok. Thank you very much.

@tlipski
Copy link

tlipski commented Jan 7, 2015

@mbertschler - I like your solution, but wouldn't it better to write in index.html something like this?

{{ range .Data.Pages }}
    {{if eq .Type "index" }}
        {{ template "partials/header.html" . }}
        {{.Content}}
        {{ template "partials/footer.html" . }}
    {{end}}
{{ end }}

@mbertschler
Copy link

@tlipski it should work that way as well. How you write that part is totally irrelevant, because /index.html will only get generated once.

@tlipski
Copy link

tlipski commented Jan 7, 2015

@mbertschler I altered it this way so next/prev/title can work properly

@spf13 spf13 modified the milestones: v0.13, v0.14 Feb 22, 2015
@codethief
Copy link

After two hours of trying to find out how to create a simple, non-blog – in that sense, actually static – website with Hugo, I finally arrived here. Thanks for the workarounds, guys!

@gutenye
Copy link

gutenye commented Jun 19, 2015

Nice workarounds, I really wish Hugo can support it by default

@anthonyfok anthonyfok modified the milestones: v0.15, v0.14 Jun 19, 2015
@irisli
Copy link

irisli commented Jun 30, 2015

👍

It would be great if Hugo had better support for homepage as a content file (and not as a layout file). On the sites I've been using Hugo on, the home page layout is the same as some other content pages.

@codethief
Copy link

@spf13 Any news regarding this issue? I would love to use Hugo for static pages.

@nikolas
Copy link
Contributor

nikolas commented Oct 19, 2015

I needed to customize some CSS only on the homepage, so I wanted to add a class to the body tag to decide whether to apply my CSS. I did this in my header.html partial:

<body class="page-{{ .Title | urlize }}">

And now I can make a CSS rule like:

body.page-title-of-my-site {
    background-color: #000;
}

that's only applied on the homepage.

@rhewitt22
Copy link

👍 for handling index page content as a first class citizen.

@fazy
Copy link

fazy commented Nov 5, 2015

After experimenting with themes, I decided to build my site from the ground up (but looking at themes for reference). It's a small, personal site, but I want to devote most of the home page to my Flickr photos feed, and relegate the blog to a sub-section. As such, the home page will be fairly bespoke, with very little blog content, while the blog section will fit well with the content/templates model used by Hugo.

So just to see it working (hello world, minimum viable product, iterate...) my entire home page is like this:

layouts/index.html

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>{{ .Site.Title }}</title>
</head>
<body lang="en">

<section id="main">
    <div>
        {{ range .Data.Pages }}
            {{if and (eq .Type "index") (eq .Title "heading" ) }}
                {{.Content}}
            {{end}}
        {{ end }}

        <hr>
        <p>Stuff baked into the template... should probably still use variables like {{ .Site.Title }}</p>
        <hr>

        {{ range .Data.Pages }}
            {{if and (eq .Type "index") (eq .Title "intro" ) }}
                {{.Content}}
            {{end}}
        {{ end }}
    </div>
</section>

Then I have the content files:

content/index/heading.md

+++
type = "index"
title = "heading"
+++

# Page heading
## Sub heading
a little bit of text maybe

content/index/intro.md

+++
type = "index"
title = "intro"
+++

# Hello,

Here is a little intro about me that I am going to place
further down the page (e.g. after a big photo).

I've basically done the same as @mbertschler (thanks!), but with the ability to have a couple of bits of content in different parts of the home page. I'm not 100% sure if I'll need that yet, but it's good to have the flexibility if I decide not to do the whole template in markdown.

Edit: I can probably do the whole home page in a single markdown file using Shortcodes for any complex bits like a Flickr carousel. Still, it might be useful to get bits of content from various places at times. ;)

@fazy
Copy link

fazy commented Nov 5, 2015

This work-around doesn't seem to work for partials. For example, if including code like this:

<title> {{ .Title }} &middot; {{ .Site.Title }} </title>

.Title is not set.

How can I determine what page I am really on so as to display the correct title?

@bep
Copy link
Member

bep commented Nov 5, 2015

Use The discussion site for questions.

@bep bep closed this as completed Nov 5, 2015
@fazy
Copy link

fazy commented Nov 5, 2015

If I delete my question above, will you re-open this feature request? I think a number of people would like to have an index page.

@bep
Copy link
Member

bep commented Nov 5, 2015

My bad ... I thought this was a new topic... Yes, this will come at some point.

@bep bep reopened this Nov 5, 2015
@fazy
Copy link

fazy commented Nov 5, 2015

That's very good to know, thanks. :) And sorry to be lazy about signing up for the forums, but I've done that now.

@mbertschler
Copy link

I would like to fix this for the next release. The question is how this could be implemented.

My proposal would be that if there is an index.md file in the content directory, that the relevant single.html template file will be used instead of the index.html file from the template. I think the index file could be a special case because this is how it always worked with html files.

What are your thoughts?

@rhewitt22
Copy link

Simple, solid solution. I think the homepage should also fall back on default/single.html too if an index.md is present but an index layout isn't defined.

Roy

On Nov 27, 2015, at 3:08 PM, Martin Bertschler notifications@github.com wrote:

I would like to fix this for the next release. The question is how this could be implemented.

My proposal would be that if there is an index.md file in the content directory, that the relevant single.html template file will be used instead of the index.html file from the template. I think the index file could be a special case because this is how it always worked with html files.

What are your thoughts?


Reply to this email directly or view it on GitHub.

@spf13
Copy link
Contributor

spf13 commented Nov 27, 2015

I think this may already be the case.
On Fri, Nov 27, 2015 at 3:36 PM Roy Hewitt notifications@github.com wrote:

Simple, solid solution. I think the homepage should also fall back on
default/single.html too if an index.md is present but an index layout
isn't defined.

Roy

On Nov 27, 2015, at 3:08 PM, Martin Bertschler notifications@github.com
wrote:

I would like to fix this for the next release. The question is how this
could be implemented.

My proposal would be that if there is an index.md file in the content
directory, that the relevant single.html template file will be used instead
of the index.html file from the template. I think the index file could be a
special case because this is how it always worked with html files.

What are your thoughts?


Reply to this email directly or view it on GitHub.


Reply to this email directly or view it on GitHub
#330 (comment).

@spf13
Copy link
Contributor

spf13 commented Nov 27, 2015

This may be part of the solution, but it doesn't resolve all the issues. it
doesn't treat index.md as the root. We also should have a general solution
for binding content to nodes.
On Fri, Nov 27, 2015 at 5:15 PM Steve Francia steve.francia@gmail.com
wrote:

I think this may already be the case.
On Fri, Nov 27, 2015 at 3:36 PM Roy Hewitt notifications@github.com
wrote:

Simple, solid solution. I think the homepage should also fall back on
default/single.html too if an index.md is present but an index layout
isn't defined.

Roy

On Nov 27, 2015, at 3:08 PM, Martin Bertschler <
notifications@github.com> wrote:

I would like to fix this for the next release. The question is how this
could be implemented.

My proposal would be that if there is an index.md file in the content
directory, that the relevant single.html template file will be used instead
of the index.html file from the template. I think the index file could be a
special case because this is how it always worked with html files.

What are your thoughts?


Reply to this email directly or view it on GitHub.


Reply to this email directly or view it on GitHub
#330 (comment).

@bep
Copy link
Member

bep commented Nov 28, 2015

See https://discuss.gohugo.io/t/node-improvements/1593

Please, no hacks just to get the home page to "somehow work".

@anthonyfok anthonyfok modified the milestones: v0.16, v0.15 Nov 30, 2015
@richie5um
Copy link

@mbertschler Thank you!

@bep
Copy link
Member

bep commented Jul 21, 2016

Will be handled in #2297.

@bep bep closed this as completed Jul 21, 2016
bep added a commit that referenced this issue Feb 10, 2018
f97826a17 Merge commit '12ecbf4a1b05c2794281f47909c836b1a005bc19'
12ecbf4a1 Squashed 'themes/gohugoioTheme/' changes from ecad8247..fe71e360
aaa7ac214 Ignore .DS_Store files
0e023ca12 Remove comments in showcase front matter
f3ba5ac87 Hartwell Insurance showcase
47aefdbda Remove unnecessary duplicated words
612693b4f Some minor language fixes
a833ba15b Spelling
5972e70a9 Revert "showcase: Even smaller file"
3479b975e showcase: Even smaller file
2272e0b83 showcase: Reduce image size
718c3c3e5 Spelling
0b954eccb showcase: Pace copy-edits
baded8064 showcase: Pace
842c1cedf Add a Showcase copyright notice
c5963edaa Update installing
4fa0b0d73 Add link to showcase template
d0f303916 Add some showcase guide content
c809789b1 Add srcset to the showcase screenshots
49d875904 Start of a template
1153de221 Clean resouerces
69f00df4c Remove the showcases
653ad5bcd Add a simple byline
c5342b5e5 Regenerate image after rebase
b80669b34 Bump version in config.toml
cd5c79c67 Fix an issue where whitespace wrap caused scrollbars on some browsers
f00547e98 Add section to the title element
aa10defed Iterating on Showcase (#330)
76a0bfbc3 Add some dummy content to some of the showcase pages
66f68964d Standardize showcase metadata
627ffa6d4 Adjust showcase image size on front page
cbc3efece Redo some showcase images
054b54cb6 Use .RelPermalink and not .URL
82ba5f1c6 Add resources
d1415795b Move showcase items in list view to a template in the layout
f34620e90 Tweak details box for mobile
df6a0bf24 Include images that changed from the column shift
02036581f Improve showcase single layout
5f7730c89 Improve styling of showcase prev/next buttons
a2b2f7731 Remove extra div that was breaking mobile layout of the showcase
b172fe5f4 Add block class to to images on mobile so they behave as expected
a4ebfec86 Add a proper RSS feed to home page
0524479e0 Move showcase images to proper Resources
0544b57df Convert showcase pages to bundles
8febaab2b Add Showcase to Home page and internal pages
26d1f4542 Fix baseURL in Netlify deploy previews
046497616 Revert "Try to fix the Netlify preview baseURL setup"
80dce17ca Revert "Add some temporary baseURL debug"
8617e8692 Add some temporary baseURL debug
371e56bce Try to fix the Netlify preview baseURL setup
1b70b3f18 Add Netlify CMS to Frontends list
d6184e71d Fix menu for "What is Hugo" page
1ae83ad3e Fix mobile menu display so it shows on mid-size displays
f60e1f750 Edited slight typo, added "of"
56b906667 Fix typo
c5bea5cbd Release 0.36
00539094e releaser: Prepare repository for 0.37-DEV
b222cbdf2 releaser: Add release notes to /docs for release of 0.36
e59d1d766 releaser: Bump versions for release of 0.36
9620aa002 docs: Add documentation for smart cropping etc.
91c3801f1 Merge commit 'c305e44f5f081e4436195923a4593e396f07cd49'
8e71ff60b releaser: Prepare repository for 0.36-DEV

git-subtree-dir: docs
git-subtree-split: f97826a17209fe3e153b7f5bbf69c511e4e13203
@github-actions
Copy link

github-actions bot commented Apr 4, 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 Apr 4, 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