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

Data files and dynamic page generation support #452

Closed
avishnyakov opened this issue May 16, 2018 · 9 comments
Closed

Data files and dynamic page generation support #452

avishnyakov opened this issue May 16, 2018 · 9 comments
Labels
type: feature request Request to add a new feature version: next Planned to do or already included in the next(1.0.0) version

Comments

@avishnyakov
Copy link

Hey guys, thanks for this amazing project. That fact that it comes with a built-in support for technical documentation is pure gold.

Looking into doco, could not find anything on how to bring custom datasets into VuePress workflow. For example, there is a bunch of YAML/JSON files somewhere in the folder which will later be used to generate some bits of contents or whole pages. There are two scenario here:

  • generating content on the page leveraging Vue inside markdown
  • generating whole pages dynamically based on incoming data

For example, here is how Middleman handles this. It exposed a global "data" object which can be used within templates.

https://middlemanapp.com/advanced/data-files/

I saw that this.$site and this.$page provides access to page metadata and front matter, but still not sure how to address custom data files access in the right way.

Could you please provide guidance on this? Updating documentation on how to handle these cases would be awesome as well.

@ulivz ulivz added the type: feature request Request to add a new feature label May 16, 2018
@ulivz
Copy link
Member

ulivz commented May 16, 2018

This could be something for the roadmap after we've finalized how the plugin system should work.

@ulivz ulivz added TBD and removed type: feature request Request to add a new feature labels May 16, 2018
@ulivz ulivz changed the title Data files and dynamic page generation support? [Feature Request] Data files and dynamic page generation support May 16, 2018
@ulivz ulivz added the type: feature request Request to add a new feature label May 16, 2018
@ulivz ulivz changed the title [Feature Request] Data files and dynamic page generation support Data files and dynamic page generation support May 16, 2018
@avishnyakov
Copy link
Author

avishnyakov commented May 17, 2018

@ulivz, sounds good.

Would you like to suggest a light option for making it happen? I am after the first case, accessing data files in the vue templates. Have examples and other files stored separately from the markdown. A few suggestion how to organize stuff will do, such as:

  • Put your files in a folder here
  • Read them with this code into a variable or whatever
  • Use this variable in the templates to render stuff

A high level idea will do, I'll figure out the coding and details.

@avishnyakov
Copy link
Author

Folks, I'd really appreciate a few tips here. Looking into storing some data in ".vuepress" folder, a bunch of json/yaml files, then reading and making them available globally across pages and vue components. If you could suggest which way to go and what to read up that is really appreciated.

@falkben
Copy link

falkben commented Jul 12, 2018

I'm curious about this too -- what did you decide to do?

@ulivz
Copy link
Member

ulivz commented Jul 12, 2018

It has been supported at the plugin API, we'll release it ASAP.

@ulivz ulivz added plugin scope version: next Planned to do or already included in the next(1.0.0) version and removed TBD labels Aug 20, 2018
@colwilson
Copy link

In the meantime, is this what you had in mind?

https://vuepress-examples.netlify.com/demos/local/

@ulivz
Copy link
Member

ulivz commented Sep 16, 2018

  1. Data files is frontmatter, you can access it via this.$page.frontmatter.
  2. Dynamic page generation support has been supported at Next

@aaronlippold
Copy link

  1. Data files is frontmatter, you can access it via this.$page.frontmatter.
  2. Dynamic page generation support has been supported at Next

Is there an example of the Dynamic page generation support?

@rufuspollock
Copy link

For anyone else looking for this, this is now very much possible thanks to additionalPages API:

https://vuepress.vuejs.org/plugin/option-api.html#additionalpages

e.g. in your config.js you can have stuff like:

const path = require('path')

module.exports = {
  additionalPages: [
    {
     path: '/readme/',
     filePath: path.resolve(__dirname, '../../README.md')
    }
  ]
}

// or ...

module.exports = {
  async additionalPages () {
    // Note that VuePress doesn't have request library built-in
    // you need to install it yourself.
    const rp = require('request-promise')
    const content = await rp('https://raw.githubusercontent.com/vuejs/vuepress/master/CHANGELOG.md')
    return [
      {
        path: '/changelog/',
        content
      }
    ]
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature request Request to add a new feature version: next Planned to do or already included in the next(1.0.0) version
Projects
None yet
Development

No branches or pull requests

6 participants