是时候表演一波真正的技术了
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
.editorconfig
.eslintrc.yml
.gitignore
.npmignore
CHANGELOG.md
LICENSE
README.md
cloc.js
index.js
package.json
yarn.lock

README.md

NuxtPress

github npm npm npm codebeat code-size

是时候表演一波真正的技术了。代码行数: 仅 255 行。

示例

地址: https://v0.chat 源码: https://github.com/assholev0/v0.chat

配置

创建 .nuxtpress.config.js (根目录下,与nuxt.config.js同级)。

module.exports = {
  source: '_source', // 默认文章目录
  per_page: 10, // 默认分页 10/页, 0 为关闭分页
};

API

$np 方法

np 是 NuxtPress 的缩写。在 Nuxt 页面中,可以这样使用:

export default {
  async asyncData({app}) {
    return {
      posts: await app.$np.posts(1)
    }
  }
}

info 基本信息

app.$np.info()

返回:

{
title: "初瘦",
description: "想当初,也瘦过。公众号:assholev0",
posts: 3,
tags: 4,
categories: 2,
wordcount: 2451
}

posts 文章列表

app.$np.posts(page)

参数:

  • page: 页码 (默认为1)

返回:

{
  "page": 1,
  "pages": 1,
  "posts": [
    {
      "excrept": "<h2>此处是摘要</h2>",
      "wordcount": 1191,
      "tags": [
        "生活"
      ],
      "category": [
        "闲聊"
      ],
      "title": "初瘦与那些他的三观不正的杂念",
      "date": "2018-09-19T07:19:29.000Z",
      "slug": "assholev0"
    }
    // 。。。
  ]
}

post 文章

app.$np.post(slug)

参数:

  • slug: 文章别名,必须

返回:

{
  "post": {
    "content": "<h2 id=\"何谓初瘦?\"><a class=\"header-anchor\" href=\"#何谓初瘦?\" aria-hidden=\"true\">#</a> 何谓初瘦?</h2>。。。。。。",
    "excrept": "<h2>此处是摘要</h2>",
    "wordcount": 1191,
    "tags": [
      "生活"
    ],
    "category": [
      "闲聊"
    ],
    "title": "初瘦与那些他的三观不正的杂念",
    "date": "2018-09-19T07:19:29.000Z",
    "slug": "assholev0"
  }
}

tags 标签

app.$np.tags(search)

参数:

  • search: 传入标签名称,查询标签下的日志 (默认为空)

返回:

{
  "tags": [
    {
      "name": "vue",
      "count": 1
    },
    {
      "name": "vuepress",
      "count": 1
    },
    {
      "name": "前端",
      "count": 1
    },
    {
      "name": "生活",
      "count": 2
    }
  ],
  "posts": [
    {
      "excrept": "<h2>此处是摘要</h2>",
      "wordcount": 1191,
      "tags": [
        "生活"
      ],
      "category": [
        "闲聊"
      ],
      "title": "初瘦与那些他的三观不正的杂念",
      "date": "2018-09-19T07:19:29.000Z",
      "slug": "assholev0"
    }
  ]
}

categories 分类

app.$np.categories(search)

参数:

  • search: 传入分类名称,查询分类下的日志 (默认为空)

返回:

{
  "categories": [
    {
      "name": "技术",
      "count": 1
    },
    {
      "name": "闲聊",
      "count": 2
    }
  ],
  "posts": [
    {
      "excrept": "<h2>此处是摘要</h2>",
      "wordcount": 1191,
      "tags": [
        "生活"
      ],
      "category": [
        "闲聊"
      ],
      "title": "初瘦与那些他的三观不正的杂念",
      "date": "2018-09-19T07:19:29.000Z",
      "slug": "assholev0"
    }
  ]
}

archives 归档

app.$np.archives()

返回:

{
  "posts": [
    {
      "wordcount": 1191,
      "tags": [
        "生活"
      ],
      "category": [
        "闲聊"
      ],
      "title": "初瘦与那些他的三观不正的杂念",
      "date": "2018-09-19T07:19:29.000Z",
      "slug": "assholev0"
    },
    // 。。。
  ]
}

TODO List

  • add Page Render
  • add API Server Middleware
  • add Request Plugin
  • add Build Hook

License

MIT