Third Party

搜索

本地搜索(基于 fuse.js)

Local Search (Based on fuse.js)

Valaxy 内置了基于 fuse.js 的离线搜索(须预先通过 valaxy fuse 构建生成本地缓存)。

valaxy fuse 默认将 fuse 生成在 public 目录下,并在 .gitignore 中添加 public/valaxy-fuse-list.json 忽略。 在执行 valaxy build 之前,会自动执行 valaxy fuse

如果你想要使用全文搜索,可参考 Options | fuse.js 进行设置。 譬如:

ts
export default defineSiteConfig({
  search: {
    enable: true,
    type: 'fuse',
  },
  fuse: {
    options: {
      keys: ['title', 'tags', 'categories', 'excerpt', 'content'],
      /**
       * @default 0.6
       * @see https://www.fusejs.io/api/options.html#threshold
       * 设置匹配阈值,越低越精确
       */
      // threshold: 0.6,
      /**
       * @default false
       * @see https://www.fusejs.io/api/options.html#ignoreLocation
       * 忽略位置
       * 这对于搜索文档全文内容有用,若无需全文搜索,则无需设置此项
       */
      ignoreLocation: true,
    },
  },
})

Valaxy has built-in local search based on fuse.js. The local cache should be generated in advance via valaxy fuse.

valaxy fuse generates fuse in the public directory by default. When executing valaxy build, valaxy fuse will be executed automatically.

使用

Setup

ts
// site.config.ts
import { defineSiteConfig } from 'valaxy'

export default defineSiteConfig({
  search: {
    enable: true,
    // 设置类型为 Fuse
    type: 'fuse',
  },
})
  • 在你的 package.json 中添加 fuse 生成脚本
ts
// site.config.ts
import { defineSiteConfig } from 'valaxy'

export default defineSiteConfig({
  search: {
    enable: true,
    // Set type to 'fuse'
    type: 'fuse',
  },
})
  • Add fuse generation script in your package.json
json
{
  "name": "yun-demo",
  "valaxy": {
    "theme": "yun"
  },
  "scripts": {
    "build": "npm run build:ssg",
    "build:ssg": "valaxy build --ssg",
    "fuse": "valaxy fuse",
    "rss": "valaxy rss"
  },
  "dependencies": {
    "valaxy": "latest",
    "valaxy-theme-yun": "latest"
  }
}

Algolia 搜索

Algolia DocSearch

Algolia 是一个在线第三方搜索服务,您需要自行申请相关 ID 和 Secret。

DocSearch 申请通常只接受技术文档。

Valaxy 提供了一个快速集成插件 valaxy-addon-algolia(目前仅支持 DocSearch)。

Algolia is an online third-party search service. You need to apply for the ID and Secret by yourself.

DocSearch Only technical document applications are accepted generally.

Valaxy provides a quick integration plug-in: valaxy-addon-algolia (Currently only DocSearch is supported).

音乐播放器

Music Player

基于 AplayerMetingJS 实现

譬如在文章中引入网易云某首歌曲(ID 为歌曲 ID):

在文章头部添加:

Implementd based on Aplayer and MetingJS

For example, add a song from Netease Cloud in a article:

Enable it in the FrontMatter of the article:

md
---
aplayer: true
---

在文中引入:

Add the component to the article:

html
<meting-js
 id="22736708"
 server="netease"
 type="song"
 theme="#C20C0C">
</meting-js>

效果如下:

Here is a demo:

More info see Option | MetingJS

谷歌统计

Google Statistics

可参见 扩展 Client 上下文|自定义扩展

你可以通过直接使用 Vue 插件的方式引入谷歌统计。

譬如:

  • 安装依赖:pnpm add vue-gtag-next
  • 新建 setup/main.ts:
ts
// setup/main.ts
import { defineAppSetup } from 'valaxy'
import { install as installGtag } from './gtag'

export default defineAppSetup((ctx) => {
  installGtag(ctx)
})
  • 新建 setup/gtag.ts:
ts
import type { UserModule } from 'valaxy'
import VueGtag, { trackRouter } from 'vue-gtag-next'

export const install: UserModule = ({ isClient, app, router }) => {
  if (isClient) {
    app.use(VueGtag, {
      property: { id: 'G-1LL0D86CY9' },
    })

    trackRouter(router)
  }
}

Refer to Custom Extensions | Extending Client Context

You can add Google Statistics by using Vue plug-in directly.

For example:

  • Install the dependency: pnpm add vue-gtag-next
  • Create setup/main.ts
ts
// setup/main.ts
import { defineAppSetup } from 'valaxy'
import { install as installGtag } from './gtag'

export default defineAppSetup((ctx) => {
  installGtag(ctx)
})
  • Create setup/gtag.ts
ts
import type { UserModule } from 'valaxy'
import VueGtag, { trackRouter } from 'vue-gtag-next'

export const install: UserModule = ({ isClient, app, router }) => {
  if (isClient) {
    app.use(VueGtag, {
      property: { id: 'G-1LL0D86CY9' },
    })

    trackRouter(router)
  }
}

More info see vue-gtag-next.

Contributors


To Be Continued.