npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

vitepress-plugin-announcement

v0.1.7

Published

vitepress plugin, Announcement, 公告窗口

Readme

vitepress-plugin-announcement

English | 简体中文

介绍文章:VitePress 公告插件开发实记 · archive · translated

使用

安装依赖 pnpm/npm/yarn

pnpm add vitepress-plugin-announcement

引入插件在 .vitepress/config.ts 配置文件中

import { defineConfig } from 'vitepress'
import { AnnouncementPlugin } from 'vitepress-plugin-announcement'

export default defineConfig({
  vite: {
    // ↓↓↓↓↓
    plugins: [
      AnnouncementPlugin({
        title: '公告',
        body: [
          { type: 'text', content: '👇公众号👇 ---👇 赞赏 👇' },
          {
            type: 'image',
            src: 'https://cdn.upyun.sugarat.top/mdImg/sugar/85c9554d023be2fcc5aab94effeef033',
            style: 'display: inline-block;width:46%;padding-right:6px'
          },
          {
            type: 'image',
            src: 'https://cdn.upyun.sugarat.top/mdImg/sugar/54eacf3e730af9c1e3542a4800a422ea',
            style: 'display: inline-block;width:46%;padding-left:6px'
          }
        ],
        footer: [
          {
            type: 'text',
            content: 'footer content'
          },
          {
            type: 'button',
            content: '作者博客',
            link: 'https://sugarat.top'
          },
          {
            type: 'button',
            content: '博客主题',
            link: 'https://theme.sugarat.top',
            props: {
              type: 'success'
            }
          },
        ],
      })
    ]
    // ↑↑↑↑↑
  }
})

更多用法

关闭后不再弹出

tip:下次配置修改后再展示

AnnouncementPlugin({
  duration: -1
})

不展示再次打开按钮

AnnouncementPlugin({
  reopen: false
})

引导闪烁

AnnouncementPlugin({
  twinkle: true
})

按钮

AnnouncementPlugin({
  title: '公告',
  body: [
    {
      type: 'button',
      content: '博客主题',
      link: 'https://theme.sugarat.top',
      props: {
        type: 'success'
      }
    },
  ],
})

修改样式

行内样式

AnnouncementPlugin({
  title: '公告',
  body: [
    {
      type: '',
      content: '',
      // ↓↓↓↓↓
      style: 'color: #000; font-size: 16px;'
      // ↑↑↑↑↑
    }
  ]
})

内部样式表

AnnouncementPlugin({
  style: `.theme-blog-popover a {
      color: var(--vp-c-brand-2);
   }
  `
})

markdown

content,title 字段支持基础 markdown 语法

  • # 标题
  • [链接](url) 链接
  • **strong** 加粗
  • *italic* 斜体
AnnouncementPlugin({
  title: '公告',
  body: [
    {
      type: 'text',
      content: '**加粗的内容 *斜体[链接](url)***'
    },
  ]
})

完整配置

import type { Ref } from 'vue'
import type { Route } from 'vitepress'

export interface AnnouncementOptions {
  /**
   * 自定义样式类名
   * @example
   * ```css
   * .theme-blog-popover a {
   *    color: var(--vp-c-brand-2);
   * }
   * ```
   */
  style?: string
  /**
   * 公告标题
   */
  title: string
  /**
   * 公告主要内容
   */
  body?: Announcement.Value[]
  /**
   * 公告底部内容
   */
  footer?: Announcement.Value[]

  /**
   * 是否只在浏览器环境渲染组件
   * @default false
   * @doc https://vitepress.dev/guide/ssr-compat#clientonly
   */
  clientOnly?: boolean

  /**
   * 展示时机控制
   *
   * -1 只展示1次;>= 0 每次都展示,一定时间后自动消失,0 不自动消失
   *
   * 配置发生改变时,会重新触发此规则
   * @default 0
   */
  duration?: number

  /**
   * 移动端自动最小化
   * @default false
   */
  mobileMinify?: boolean

  /**
   * 支持重新打开(右上角 icon 悬浮)
   * @default true
   */
  reopen?: boolean

  /**
   * 是否打开闪烁提示,通常需要和 reopen 搭配使用
   * @default false
   */
  twinkle?: boolean

  /**
   * 设置展示图标,svg
   */
  icon?: string

  /**
   * 设置关闭图标,svg
   */
  closeIcon?: string

  /**
   * 自定义展示策略
   * @param to 切换到的目标路由
   */
  onRouteChanged?: (to: Route, show: Ref<boolean>) => void

  /**
   * 国际化
   */
  locales?: Record<string, Omit<AnnouncementOptions, 'locales'>>
}

export declare namespace Announcement {
  export interface Title {
    type: 'title'
    content: string
    style?: string
  }

  export interface Text {
    type: 'text'
    content: string
    style?: string
  }

  export interface Image {
    type: 'image'
    src: string
    style?: string
  }

  export interface Button {
    type: 'button'
    link: string
    content: string
    style?: string
    props?: {
      type: 'primary' | 'success' | 'danger' | 'warning' | 'info' | 'text' | 'default'
    }
  }

  export type Value = Title | Text | Image | Button
}

Thanks

样式参考了 reco-1.x 主题 中的 @vuepress-reco/vuepress-plugin-bulletin-popover 插件