Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Index Page" feature #794

Open
kiaking opened this issue Jun 14, 2022 · 5 comments
Open

Add "Index Page" feature #794

kiaking opened this issue Jun 14, 2022 · 5 comments
Labels
enhancement New feature or request

Comments

@kiaking
Copy link
Member

kiaking commented Jun 14, 2022

It would be great to have index page where it lists all subpage headings like Vue.js API page.

This feature would be especially useful for pages like API and config references. The idea is to fetch crawl pages based on sidebar menu structure, and list all headings with in the page, separating them into each section (box in Vue.js API example).

Not 100% sure how Vue.js website is doing this at the moment, but we should first come up with good API design (how to configure this page).

@kiaking kiaking added the enhancement New feature or request label Jun 14, 2022
@kiaking kiaking added this to the v1.0.0 milestone Jun 14, 2022
@poyoho poyoho mentioned this issue Aug 21, 2022
@yyx990803
Copy link
Member

This is done using the "static data import" feature: https://github.com/vuejs/docs/blob/main/src/api/api.data.ts

I believe it's not fully documented at the moment, but essentially:

  • Create a file ending in .data.ts or .data.js

  • In the file, export default an object:

    // example.data.ts
    interface Data {}
    
    export declare const data: Data
    
    export default {
      watch: [/* globs to watch, can be relative */],
      async load(): Promise<Data> {
        // read the files, return transformed data
      }
    }
  • In any other file:

    <script setup>
    import { data } from './example.data.js'
    console.log(data)
    </script>

The data loader file is only executed at build time - the module is directly transformed into inlined JSON.

@isorna
Copy link

isorna commented May 11, 2023

Hi, I've tried to follow the documentation at Build-Time Data Loading, and after some problems I reallized that if I use the .js extension on the import, vite doesn't find the generated file:

<script setup>
import { data } from './example.data'
console.log(data)
</script>

I'd like to ask for a clarification on the documentation site, and also some lines explaining where should the .data.ts file be, as it's not clear that it mus be located on the same folder as the .md files it uses.

Regards

@alephpi
Copy link

alephpi commented May 29, 2023

Hi, I've tried to follow the documentation at Build-Time Data Loading, and after some problems I reallized that if I use the .js extension on the import, vite doesn't find the generated file:

<script setup>
import { data } from './example.data'
console.log(data)
</script>

I'd like to ask for a clarification on the documentation site, and also some lines explaining where should the .data.ts file be, as it's not clear that it mus be located on the same folder as the .md files it uses.

Regards

Today I met same issue as you mentioned. Based on stupid tries, here are some experience (but I don't know why):

  1. .data.ts could not be necessarily on the same folder. As I could import it from ../.data for example.
  2. make sure it only has the default export
  3. do not add extension .js/.ts
  4. wherever it is, always use glob pattern relative to project root

@brc-dd brc-dd mentioned this issue Jul 28, 2023
4 tasks
@brc-dd
Copy link
Member

brc-dd commented Aug 3, 2023

Let's track #2699 here itself.

@github-actions github-actions bot added the stale label Sep 16, 2023
@kevindamm
Copy link

It seems that this has been addressed with the documentation added about data-loading, especially the section on createContentLoader

I think this bug can be closed.

@github-actions github-actions bot removed the stale label Jun 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants