Blog

文章

文章是博客的核心。采用 markdown 的形式。

读取文章

读取文章列表

const { data } = await useAsyncData('index', () => queryContent()
  .where({ _extension: 'md', published: true })
  .sort({ 'dates.created': -1 })
  .only(['title', 'description', 'cover', 'dates', '_path'])
  .limit(10).find())

获取文章内容

const { data: page } = await useAsyncData(route.path, () => queryContent(route.path)
  .where({ _extension: 'md' })
  .findOne())

markdown 文件介绍

markdown 文件主要有两部分

文章元数据

采用 Front-matter 的形式

title: 文章
description: 
cover:
  src: 
  alt: 
tags:
  - blog  
dates: 
  created: 2024-08-25
  updated: 2024-09-10
published: true

文章内容