VuePress Documentation Guide
website·Indexed 29 days ago
https://yiov.github.io/A guide for using VuePress to create markdown-centered static sites. Covers installation, configuration, Frontmatter, components, styling via CSS variables, plugin integration, and search setup using @vuepress/plugin-docsearch@next with Algolia or self-hosted crawlers.
What's inside VuePress
- VuePress is a Markdown-centric static site generator. It allows users to write content (such as documentation or blogs) using Markdown, which VuePress then converts into a static website for display.
Overview of VuePress core features
VuePress is a static site generator that focuses on a Markdown-centric project structure with minimal configuration. Key features include:
- Vue-Driven: Allows the use of Vue components directly within Markdown files and enables the development of custom themes using Vue.
- High Performance: Pre-renders every page into static HTML for fast initial load, while functioning as a Single Page Application (SPA) once loaded in the browser.
Understand the basic structure of a component
Components are composed of three primary parts that map to standard web technologies:<template>for HTML structure,<script>for JavaScript logic, and<style>for CSS styling.VuePress Core Features Overview
VuePress is a static site generator with the following characteristics:
- Vue-Powered: Supports Vue components within Markdown and custom themes built with Vue.
- Performance: Generates pre-rendered static HTML for each page and functions as a Single Page Application (SPA) once loaded.
- Extensibility: Provides a default theme, supports community themes, and offers a flexible plugin API for plug-and-play features.
- Bundlers: Uses Vite as the default bundler, but also supports Webpack.
Run a self-hosted DocSearch crawler using Docker
To index your site without official approval, you can run thealgolia/docsearch-scraperimage. This requires an Algolia account, a created index, and thejqtool installed on your host system to pass the configuration JSON as an environment variable.# 1. Install jq for JSON parsing yum install jq -y # 2. Create .env file echo "APPLICATION_ID=your_app_id API_KEY=your_admin_api_key" > .env # 3. Run the scraper docker run -it --env-file=.env -e "CONFIG=$(cat config.json | jq -r tostring)" algolia/docsearch-scraperImport external code snippets into Markdown
Use the@[code]syntax to import code from other files. You can specify line ranges, languages, and highlighting. To handle complex paths, usehandleImportPathin themarkdown.importCodeconfiguration.<!-- Basic import --> @[code](./.vuepress/config.ts) <!-- Import lines 1-10 with ts language --> @[code ts{1-10}](./.vuepress/config.ts) <!-- Complex: lines 3-10 highlight, ts language, line 3 highlighted, no line numbers --> @[code{3-10} ts{3}:no-line-numbers](./.vuepress/config.ts)<!-- Configuration for custom path handling -->
import { getDirname, path } from '@vuepress/utils' const __dirname = getDirname(import.meta.url) export default defineUserConfig({ markdown: { importCode: { handleImportPath: (str) => str.replace(/^@vuepress/, path.resolve(__dirname, './')), }, }, })Install @vuepress/plugin-docsearch@next
Install the DocSearch plugin for VuePress using one of the following package managers. If installation fails, ensure you have a stable network connection (or use a proxy/VPN).# Using pnpm pnpm add -D @vuepress/plugin-docsearch@next # Using yarn yarn add -D @vuepress/plugin-docsearch@next # Using npm npm i -D @vuepress/plugin-docsearch@nextConfigure a self-built Algolia DocSearch crawler
When implementing a self-built crawler for DocSearch, you must define a configuration file that specifies how the crawler identifies content and categorizes pages. Key requirements include providing adefaultselector and ensuringattributesForFacetingincludes bothtagsandlangto enable search functionality for the crawled data.{ "index_name": "yiov", "start_urls": [ { "url": "https://vuepress.yiov.top/guide/getting-started.html", "selectors_key": "getting-started", "tags": ["getting-started"] }, "https://vuepress.yiov.top/" ], "stop_urls": [""], "selectors": { "getting-started": { "lvl0": { "selector": "", "default_value": "快速上手" }, "lvl1": ".theme-default-content h1", "lvl2": ".theme-default-content h2", "lvl3": ".theme-default-content h3", "lvl4": ".theme-default-content h4", "lvl5": ".theme-default-content h5", "lvl6": ".theme-default-content h6", "text": ".theme-default-content p, .theme-default-content li", "lang": { "selector": "/html/@lang", "type": "xpath", "global": true } }, "default": { "lvl0": { "selector": "", "default_value": "前言" }, "lvl1": ".theme-default-content h1", "lvl2": ".theme-default-content h2", "lvl3": ".theme-default-content h3", "lvl4": ".theme-default-content h4", "lvl5": ".theme-default-content h5", "lvl6": ".theme-default-content h6", "text": ".theme-default-content p, .theme-default-content li", "lang": { "selector": "/html/@lang", "type": "xpath", "global": true } } }, "custom_settings": { "attributesForFaceting": [ "lang", "tags" ] } }Install @vuepress/plugin-docsearch@next
Install the DocSearch plugin for VuePress using your preferred package manager. If installation fails, ensure you have a stable network connection (or a proxy/VPN).# Using pnpm pnpm add -D @vuepress/plugin-docsearch@next # Using yarn yarn add -D @vuepress/plugin-docsearch@next # Using npm npm i -D @vuepress/plugin-docsearch@nextReference images and public assets
Images can be referenced via relative paths or from thepublicdirectory. Assets in thepublicdirectory are copied to the root of the generated site and can be accessed via absolute paths starting with/.<!-- Relative path to image in same directory -->  <!-- Image in public directory (e.g., .vuepress/public/images/hero.png) -->  <!-- Using $withBase for theme development --> <img :src="$withBase('/images/logo.png')" alt="VuePress Logo">Configure a self-hosted Algolia DocSearch crawler
When implementing a self-hosted crawler for DocSearch, you must define a configuration file that specifies how the crawler identifies content and categorizes pages. Key configuration requirements include:
- index_name: The name of the search index.
- start_urls: A list of URLs to crawl. You can use
selectors_keyandtagsto categorize specific pages. - selectors: Defines the CSS selectors for different heading levels (
lvl1throughlvl6) and the main content text. Adefaultselector group is mandatory for the crawler to function. - stop_urls: A list of URLs that the crawler should ignore.
- attributesForFaceting: Must include
tagsandlangto enable search filtering and faceting functionality. - default_value: The default value displayed for a category when no specific value is found.
{ "index_name": "yiov", "start_urls": [ { "url": "https://vuepress.yiov.top/guide/getting-started.html", "selectors_key": "getting-started", "tags": ["getting-started"] }, "https://vuepress.yiov.top/" ], "stop_urls": [""], "selectors": { "getting-started": { "lvl0": { "selector": "", "default_value": "Quick Start" }, "lvl1": ".theme-default-content h1", "lvl2": ".theme-default-content h2", "lvl3": ".theme-default-content h3", "lvl4": ".theme-default-content h4", "lvl5": ".theme-default-content h5", "lvl6": ".theme-default-content h6", "text": ".theme-default-content p, .theme-default-content li", "lang": { "selector": "/html/@lang", "type": "xpath", "global": true } }, "default": { "lvl0": { "selector": "", "default_value": "Preface" }, "lvl1": ".theme-default-content h1", "lvl2": ".theme-default-content h2", "lvl3": ".theme-default-content h3", "lvl4": ".theme-default-content h4", "lvl5": ".theme-default-content h5", "lvl6": ".theme-default-content h6", "text": ".theme-default-content p, .theme-default-content li", "lang": { "selector": "/html/@lang", "type": "xpath", "global": true } } }, "custom_settings": { "attributesForFaceting": [ "lang", "tags" ] } }Index content using official Algolia DocSearch service
For public repositories, you can apply for Algolia's official crawler service:
- Apply at https://docsearch.algolia.com/ by providing your site URL, email, and repository link.
- After approval (typically 6-7 hours), register your account via the invitation email.
- In the Algolia dashboard, navigate to Search > Index to accept the application.
- If records are not appearing, use the Crawler dashboard (https://crawler.algolia.com/) to debug. Ensure the CSS selectors match your site's content. For VuePress default themes, replace
.content_defaultwith.theme-default-contentin the crawler editor. - Once data is synced, retrieve the
Search API Keyfrom the API Keys section for use in yourconfig.ts.