Skip to content

Commit

Permalink
refactor(index): support _index.md (#313)
Browse files Browse the repository at this point in the history
* refactor(index): support _index.md

re-implement #119 - the Hugo way of displaying front matter - without
breaking index-about.md (#179)

https://gohugo.io/content-management/organization/#index-pages-_indexmd

if _index.md exists (and has content), print it
else, if index-about.md exists (without checking for file contents), print it

* style(css): rename markdown-content class

* docs: update _index.md filename

* style(index): remove hr
  • Loading branch information
jamesericdavidson authored Feb 1, 2025
1 parent 3c15d83 commit 98e0b3a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions assets/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ table td {
transition: fill 0.15s ease;
}

.markdown-content {
.home-content {
line-height: 1.25;
width: 80%;
margin: 0 auto;
Expand Down Expand Up @@ -593,7 +593,7 @@ table td {
width: auto;
}

.markdown-content, .home-posts {
.home-content, .home-posts {
width: auto;
margin: 0;
}
Expand Down
3 changes: 2 additions & 1 deletion exampleSite/content/posts/theme-documentation-advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ The `weight` attribute can be added in the markdown metadata for `post` types. W
### About description text

In extension to the basic configuration with the `description` field, it's also possible to write the about section using markdown.
Create a file called `index-about.md` in the `content` directory and write your content there.

Create a file called `_index.md` in the `content` directory and write your content there.

> **Attention**: Don't use frontmatter in this file. It would also render it.
Expand Down
2 changes: 1 addition & 1 deletion exampleSite/content/posts/theme-documentation-basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ Examples are available in the [advanced documentation](/posts/theme-documentatio

### Display content on the home page

Markdown content in `content/index-about.md` will be rendered on the home page, below the social icons.
Markdown content in `content/_index.md` will be rendered on the home page, below the social icons.

### Display posts on the home page

Expand Down
10 changes: 6 additions & 4 deletions layouts/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ <h2>{{ .Site.Params.Description }}</h2>
</div>
{{ end }}

{{ if os.FileExists "index-about.md" }}
<div class="markdown-content">
{{ readFile "index-about.md" | markdownify }}
</div>
{{ if (or
(and (fileExists "content/_index.md") .Content)
(fileExists "content/index-about.md")) }}
<section class="home-content">
{{ or .Content (readFile "index-about.md" | markdownify) }}
</section>
{{ end }}

{{ if isset .Site.Params "showpostsonhomepage" }}
Expand Down

0 comments on commit 98e0b3a

Please sign in to comment.