question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Loading sub-directory content as categories

See original GitHub issue

Hi, I’m trying to write help articles based on a series of folders and content files within them, for example:

content/
├─ help/
│  ├─ account/
│  │  ├─ introduction.md
│  │  ├─ all-about-accounts.md
│  ├─ domains/
│  │  ├─ introduction.md
│  │  ├─ all-about-domains.md
│  ├─ monitors/
│  │  ├─ introduction.md
│  │  ├─ all-about-monitors.md

My sub-folders are my categories, and each introduction.md file is it’s meta details which can then be displayed on some blog page showing all the categories. All the other files in those folders are the individual posts.

I want my URLs for instance to be: /help/account/all-about-introduction but I’m having trouble displaying and obtaining the content for each of those using the fetch() method.

I’ve got a page and folder set up like this:

pages/
├─ help/
│  ├─ index.vue
│  ├─ _slug/
│  │  ├─ _slug.vue

And my async function to try and get data from my category folders within /_slug/_slug.vue is:

async asyncData ({ $content, params }) {
  const guide = await $content('help/account', params.slug)
                      .fetch()

  return {
    guide
  }
}

How can I achieve this?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
NozomuIkutacommented, Nov 22, 2020

@sts-ryan-holton

If I understand what you mean correctly, you want to show like this, don’t you?

<!-- Each list item is a link to introduction page -->
- Category 1 (1)
- Category 2 (2)

If so, taking a look at how Theme Docs renders its left sidebar will be helpful.

First, Theme Docs fetches all the pages and group them by category property defined in the front matter (code). Second, Theme Docs iterates the object, where key is category and value is an array of documents, with nested v-for (code).

Here is a simplified demo (CodeSandbox).

Note that Theme Docs guarantees the order of categories and pages by defining position in each document and setting a sortBy() query when fetching.

By the way, you might want to refer to Fetching content page of the official site, so that you will come up with a variety of ways of fetching as you want.

0reactions
sts-ryan-holtoncommented, Nov 25, 2020

@NozomuIkuta I’ve implemented a strategy into my website to achieve the above as per your suggestions and it seems to work! You can check out the Help section of my website if you’re interested 😃 https://domain-monitor.io/

Read more comments on GitHub >

github_iconTop Results From Across the Web

Loading files from multiple subfolders with in same folder
Hi With in working directory I have a main folder folder called 'monthyr', with in main folder I have sub folders for each...
Read more >
Jekyll: View all Folders & Subfolders as Category and Sub ...
I am lookin for a way to display: comic->subcomics->episode->.jpg files . Currently the theme supports only viewing of episode->.jpg files .
Read more >
Selecting and loading files from multiple subfolders using ...
I would like to select the Donor folder using uigetdir, then it goes through ROI1, separates Channel 2 from Channel 3, then add...
Read more >
Can't load lists or singles in a sub directory - HUGO
I have 'content/media/blogs' and inside those I have an _index.md. Then I created a layout with and singles / list html in both...
Read more >
Subdomain or Subdirectory? What They Are & How They ...
Subdirectory. A subdomain compartmentalizes your website so you can establish specific content types that are distinct from your root domain. On ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found