Only display md files in directory?

Although I have been using Caddy for a year, I am suddenly stuck on what is likely an embarrassingly simple issue.

I have used - with no modification - the markdown caddy example .

The problem is that on the index page, it renders everything else in the directory, such as the templates, styles, .git etc.:

I suspect that this is a template issue, but I am not sure. What I could like is to only display as link any *.md file present in the root directory. I have an extremely simple situation in mind that should not require a subdirectory where all the md reside.

Thank you for your attention and time.

Can you use the ‘browse’ directive?

Thank you, @tobya, for your reply. Do you mean I should use the browse directive on the index? if so, then the same issue persists: lots of irrelevant stuff shows up on the frontpage.

What I am hoping to do is a simple folder structure where caddy renders the md files as markdowns:

If I move the ./templates ./styles elsewhere, I get a 500 error. Leaving them in the directory, they are rendered on index.html.

I am wondering if this bit of the template could be tweaked to only display md files in the range. But after trying to work through the go templates, I have not found a way to do so yet.

 {{range .Files}}
            {{if ne .Name "" }}
                        {{if not .IsDir }}
                    <h3><a href="{{.Name}}">{{.Name}}</a></h3>

Simple enough to achieve - you can use the .Ext template action and a simple comparison.

{{if ne ".md" (.Ext .Name)}}
    {{/* do stuff */}}
1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.