Merged
搭建 VitePress 文档站点,实现从 AscendC 源码自动生成 API 文档的能力 #2547
CruiterAdd on May 23
搭建 VitePress 文档站点,实现从 AscendC 源码自动生成 API 文档的能力 #2547
Merged
Merged fromprintfscanfmain/asc-devkitdoc-previewintocann/asc-devkitmaster
Total: 18 files changed+13973-0
Adocs/vitepress/docs/.vitepress/config.mjs+342-0File content is under review, please try again later
| @@ -0,0 +1,56 @@ | |||
| 1 | +<script setup> | ||
| 2 | +import { ref, onMounted, onUnmounted } from 'vue' | ||
| 3 | + | ||
| 4 | +const visible = ref(false) | ||
| 5 | + | ||
| 6 | +function onScroll() { | ||
| 7 | + visible.value = window.scrollY > 400 | ||
| 8 | +} | ||
| 9 | + | ||
| 10 | +function scrollToTop() { | ||
| 11 | + window.scrollTo({ top: 0, behavior: 'smooth' }) | ||
| 12 | +} | ||
| 13 | + | ||
| 14 | +onMounted(() => window.addEventListener('scroll', onScroll)) | ||
| 15 | +onUnmounted(() => window.removeEventListener('scroll', onScroll)) | ||
| 16 | +</script> | ||
| 17 | + | ||
| 18 | +<template> | ||
| 19 | + <button | ||
| 20 | + v-show="visible" | ||
| 21 | + class="back-to-top" | ||
| 22 | + @click="scrollToTop" | ||
| 23 | + title="返回顶部" | ||
| 24 | + > | ||
| 25 | + <svg width="20" height="20" viewBox="0 0 20 20" fill="currentColor"> | ||
| 26 | + <path d="M10 3.5L3.5 10h4v6h5v-6h4z"/> | ||
| 27 | + </svg> | ||
| 28 | + </button> | ||
| 29 | +</template> | ||
| 30 | + | ||
| 31 | +<style scoped> | ||
| 32 | +.back-to-top { | ||
| 33 | + position: fixed; | ||
| 34 | + bottom: 40px; | ||
| 35 | + right: 40px; | ||
| 36 | + width: 44px; | ||
| 37 | + height: 44px; | ||
| 38 | + border: 1px solid var(--vp-c-divider); | ||
| 39 | + border-radius: 50%; | ||
| 40 | + background: var(--vp-c-bg-soft); | ||
| 41 | + color: var(--vp-c-text-2); | ||
| 42 | + cursor: pointer; | ||
| 43 | + display: flex; | ||
| 44 | + align-items: center; | ||
| 45 | + justify-content: center; | ||
| 46 | + z-index: 100; | ||
| 47 | + transition: all 0.3s; | ||
| 48 | + box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); | ||
| 49 | +} | ||
| 50 | + | ||
| 51 | +.back-to-top:hover { | ||
| 52 | + border-color: var(--vp-c-brand-1); | ||
| 53 | + color: var(--vp-c-brand-1); | ||
| 54 | + box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); | ||
| 55 | +} | ||
| 56 | +</style> | ||
| @@ -0,0 +1,72 @@ | |||
| 1 | +<script setup> | ||
| 2 | +import { ref, watch, onMounted, nextTick } from 'vue' | ||
| 3 | +import { useRoute } from 'vitepress' | ||
| 4 | + | ||
| 5 | +const route = useRoute() | ||
| 6 | +const isApiPage = ref(false) | ||
| 7 | + | ||
| 8 | +const filterOptions = [ | ||
| 9 | + { value: 'all', label: '全量' }, | ||
| 10 | + { value: '950', label: '950' }, | ||
| 11 | +] | ||
| 12 | + | ||
| 13 | +const selectedFilter = ref('all') | ||
| 14 | + | ||
| 15 | +function loadSavedFilter() { | ||
| 16 | + try { | ||
| 17 | + const saved = localStorage.getItem('cann-filter-selection') | ||
| 18 | + if (saved && filterOptions.some(o => o.value === saved)) { | ||
| 19 | + selectedFilter.value = saved | ||
| 20 | + } | ||
| 21 | + } catch {} | ||
| 22 | +} | ||
| 23 | + | ||
| 24 | +function applyFilter() { | ||
| 25 | + if (typeof document === 'undefined') return | ||
| 26 | + | ||
| 27 | + const content = document.querySelector('.vp-doc') | ||
| 28 | + if (!content) return | ||
| 29 | + | ||
| 30 | + const allFilterDivs = content.querySelectorAll('[data-filter]') | ||
| 31 | + | ||
| 32 | + if (selectedFilter.value === 'all') { | ||
| 33 | + allFilterDivs.forEach(el => { el.style.display = '' }) | ||
| 34 | + } else { | ||
| 35 | + allFilterDivs.forEach(el => { | ||
| 36 | + el.style.display = el.getAttribute('data-filter') === selectedFilter.value ? '' : 'none' | ||
| 37 | + }) | ||
| 38 | + } | ||
| 39 | +} | ||
| 40 | + | ||
| 41 | +function onFilterChange() { | ||
| 42 | + localStorage.setItem('cann-filter-selection', selectedFilter.value) | ||
| 43 | + applyFilter() | ||
| 44 | +} | ||
| 45 | + | ||
| 46 | +onMounted(async () => { | ||
| 47 | + loadSavedFilter() | ||
| 48 | + if (route.path.startsWith('/api/')) { | ||
| 49 | + isApiPage.value = true | ||
| 50 | + } | ||
| 51 | + await nextTick() | ||
| 52 | + setTimeout(applyFilter, 100) | ||
| 53 | +}) | ||
| 54 | + | ||
| 55 | +watch(() => route.path, async (path) => { | ||
| 56 | + isApiPage.value = path.startsWith('/api/') | ||
| 57 | + if (isApiPage.value) { | ||
| 58 | + await nextTick() | ||
| 59 | + setTimeout(applyFilter, 200) | ||
| 60 | + } | ||
| 61 | +}, { immediate: true }) | ||
| 62 | +</script> | ||
| 63 | + | ||
| 64 | +<template> | ||
| 65 | + <div class="cann-filter-bar" :class="{ hidden: !isApiPage }"> | ||
| 66 | + <select v-model="selectedFilter" class="filter-select" :disabled="!isApiPage" @change="onFilterChange"> | ||
| 67 | + <option v-for="opt in filterOptions" :key="opt.value" :value="opt.value"> | ||
| 68 | + {{ opt.label }} | ||
| 69 | + </option> | ||
| 70 | + </select> | ||
| 71 | + </div> | ||
| 72 | +</template> | ||
Adocs/vitepress/docs/.vitepress/theme/SearchBox.vue+236-0File content is under review, please try again later
Adocs/vitepress/docs/.vitepress/theme/filter.css+68-0File content is under review, please try again later
Adocs/vitepress/docs/.vitepress/theme/index.js+15-0File content is under review, please try again later
| @@ -0,0 +1,38 @@ | |||
| 1 | +--- | ||
| 2 | +layout: home | ||
| 3 | +pageClass: home-layout | ||
| 4 | + | ||
| 5 | +hero: | ||
| 6 | + name: Ascend C | ||
| 7 | + text: 算子开发指南 | ||
| 8 | + tagline: Ascend C 编程语言开发文档 | ||
| 9 | + actions: | ||
| 10 | + - theme: brand | ||
| 11 | + text: 开始阅读 | ||
| 12 | + link: /guide/ | ||
| 13 | + - theme: alt | ||
| 14 | + text: 入门教程 | ||
| 15 | + link: /guide/入门教程/Ascend-C概述与学习路径 | ||
| 16 | + | ||
| 17 | +features: | ||
| 18 | + - icon: 🚀 | ||
| 19 | + title: 入门教程 | ||
| 20 | + details: 从环境准备到 HelloWorld,快速上手 Ascend C 算子开发。 | ||
| 21 | + link: /guide/入门教程/Ascend-C概述与学习路径 | ||
| 22 | + - icon: 📖 | ||
| 23 | + title: 编程指南 | ||
| 24 | + details: SIMD/SIMT 编程模型、编译运行、语言扩展、调试调优完整指南。 | ||
| 25 | + link: /guide/编程指南/本文档组织结构 | ||
| 26 | + - icon: 🔧 | ||
| 27 | + title: 算子实践参考 | ||
| 28 | + details: 功能调试、性能分析、优秀实践案例,覆盖 SIMD/SIMT 算子实现与优化。 | ||
| 29 | + link: /guide/算子实践参考/本文档组织结构 | ||
| 30 | + - icon: 🔄 | ||
| 31 | + title: 跨代迁移指南 | ||
| 32 | + details: Ascend C API 兼容策略,2201 到 3510 架构迁移指导。 | ||
| 33 | + link: /guide/跨代迁移兼容性指南/概述 | ||
| 34 | + - icon: 📦 | ||
| 35 | + title: Ascend C API | ||
| 36 | + details: SIMD API、SIMT API、AI CPU API、Utils API 等完整接口参考。 | ||
| 37 | + link: /api/README | ||
| 38 | +--- | ||
| @@ -0,0 +1,19 @@ | |||
| 1 | +#!/usr/bin python3 | ||
| 2 | +# -*- coding: UTF-8 -*- | ||
| 3 | +# ---------------------------------------------------------------------------------------------------------- | ||
| 4 | +# Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 5 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 6 | +# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 7 | +# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 8 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 9 | +# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 10 | +# See LICENSE in the root of the software repository for the full text of the License. | ||
| 11 | +# ---------------------------------------------------------------------------------------------------------- | ||
| 12 | + | ||
| 13 | + | ||
| 14 | +__version__ = "0.1.0" | ||
| 15 | +__all__ = ["markdown_to_html", "gfm_to_html", "parse_file", "parse_string", "render_html"] | ||
| 16 | + | ||
| 17 | +from .parser import markdown_to_html, gfm_to_html, parse_file, parse_string, render_html | ||
| 18 | + | ||
| 19 | + | ||