Skip to content

How to get markdown content in layout? #93

Answered by ElMassimo
kecrily asked this question in Q&A
Discussion options

You must be logged in to vote

There are two main ways to achieve this, you can use a remark plugin, or you can render the markdown page and process the resulting text vnodes to count the words.

I recommend that you try the first one. For example, using remark-reading-time:

import { defineConfig } from 'iles'

let namedPlugins

export default defineConfig({
  configResolved (config) {
    namedPlugins = config.namedPlugins
  },
  markdown: {
    remarkPlugins: [
      'remark-reading-time',
      () => (ast, vfile) => {
        const page = namedPlugins.pages.api.pageForFilename(vfile.path)
        page.frontmatter.meta.readingTime = vfile.data.readingTime
      },
    ],
  },
})

and then:

<template>
  <div>Reading Tim…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by ElMassimo
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