Skip to content

Custom Path Name for Collections #509

Answered by btihen
btihen asked this question in Q&A
Discussion options

You must be logged in to vote

Its quite a hack, but this does what I was trying for:

Lets make a news file:

mkdir src/news
touch src/news/breaking.md
---
layout: page
title: Breaking
date: 2022-03-07
---

**Breaking News**
EOF

If go to: localhost:4000/news/breaking we should see our page.

Now lets make an index page that collects all the 'news' files.

touch src/news/index.md
cat <<EOF>>src/news/index.md
---
layout: page
title: News
date: 2022-03-07
---

**Some articles**

<% full_path, current_page = File.split(page.path) %>
<% path_list = Dir[full_path + "/*.md"].reject { |p| p.include?(current_page) } %>
<% file_list = path_list.map { |p| File.split(p).last.split('.').first } %>
<% title_list = path_list.map { |f| F…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@jaredcwhite
Comment options

@btihen
Comment options

Answer selected by btihen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants