Skip to content

Commit 98e0b3a

Browse files
refactor(index): support _index.md (#313)
* 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
1 parent 3c15d83 commit 98e0b3a

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

assets/css/main.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ table td {
444444
transition: fill 0.15s ease;
445445
}
446446

447-
.markdown-content {
447+
.home-content {
448448
line-height: 1.25;
449449
width: 80%;
450450
margin: 0 auto;
@@ -593,7 +593,7 @@ table td {
593593
width: auto;
594594
}
595595

596-
.markdown-content, .home-posts {
596+
.home-content, .home-posts {
597597
width: auto;
598598
margin: 0;
599599
}

exampleSite/content/posts/theme-documentation-advanced.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ The `weight` attribute can be added in the markdown metadata for `post` types. W
8484
### About description text
8585

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

8990
> **Attention**: Don't use frontmatter in this file. It would also render it.
9091

exampleSite/content/posts/theme-documentation-basics.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ Examples are available in the [advanced documentation](/posts/theme-documentatio
255255

256256
### Display content on the home page
257257

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

260260
### Display posts on the home page
261261

layouts/index.html

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ <h2>{{ .Site.Params.Description }}</h2>
2929
</div>
3030
{{ end }}
3131

32-
{{ if os.FileExists "index-about.md" }}
33-
<div class="markdown-content">
34-
{{ readFile "index-about.md" | markdownify }}
35-
</div>
32+
{{ if (or
33+
(and (fileExists "content/_index.md") .Content)
34+
(fileExists "content/index-about.md")) }}
35+
<section class="home-content">
36+
{{ or .Content (readFile "index-about.md" | markdownify) }}
37+
</section>
3638
{{ end }}
3739

3840
{{ if isset .Site.Params "showpostsonhomepage" }}

0 commit comments

Comments
 (0)