]> git.ipfire.org Git - thirdparty/vuejs/pinia.git/commitdiff
docs: no longer needed patch for duplicated id
authorEduardo San Martin Morote <posva13@gmail.com>
Thu, 3 Aug 2023 08:18:33 +0000 (10:18 +0200)
committerEduardo San Martin Morote <posva13@gmail.com>
Thu, 3 Aug 2023 08:18:33 +0000 (10:18 +0200)
packages/docs/typedoc-markdown.js

index 05e7fce446f7a7803df755fec4dab119e43c1cc6..5d369a435791618f206c5e0971e2eda15b2a2970 100644 (file)
@@ -1,10 +1,9 @@
-const _fs = require('fs')
-const path = require('path')
+// @ts-check
+const fs = require('node:fs/promises')
+const path = require('node:path')
 const TypeDoc = require('typedoc')
 const { PageEvent } = TypeDoc
 
-const fs = _fs.promises
-
 const DEFAULT_OPTIONS = {
   // disableOutputCheck: true,
   cleanOutputDir: true,
@@ -45,55 +44,13 @@ exports.createTypeDocApp = function createTypeDocApp(config = {}) {
      * @param {import('typedoc/dist/lib/output/events').PageEvent} page
      */
     (page) => {
-      if (page.url !== 'index.md' && page.contents) {
-        page.contents = prependYAML(page.contents, {
-          // TODO: figure out a way to point to the source files?
-          editLink: false,
-        })
-      }
-
-      // avoid duplicated id titles
-      if (page.contents) {
-        const lines = page.contents.split('\n')
-        const titleStack = []
-        let currentLevel = 0
-        const TITLE_LEVEL = /^#+/
-        const existingIds = new Map()
-        for (let i = 0; i < lines.length; i++) {
-          const line = lines[i]
-          if (!line.startsWith('#')) continue
-          const level = line.match(TITLE_LEVEL)[0].length
-
-          // remove extra levels
-          if (level <= currentLevel) {
-            titleStack.splice(level - 1)
-          }
-          // add the current title
-          titleStack.push(line.slice(level).trim())
-          currentLevel = level
-
-          // no need to add ids to h1
-          if (level < 2) continue
-
-          // ignore the root level (h1) to match the sidebar
-          const slugifiedTitle = slugify(titleStack.slice(1).join('-'))
-            // ensure the link is valid vuejs/router#1743
-            .replaceAll('\\', '')
-          let id
-          if (existingIds.has(slugifiedTitle)) {
-            const current = existingIds.get(slugifiedTitle)
-            existingIds.set(slugifiedTitle, current + 1)
-            id = ` %{#${slugifiedTitle}_${current + 1}}%`
-          } else {
-            existingIds.set(slugifiedTitle, 0)
-            id = ` %{#${slugifiedTitle}}%`
-          }
-          const newLine = line + id
-          lines.splice(i, 1, newLine)
-        }
-
-        page.contents = lines.join('\n')
+      if (!page.contents) {
+        return
       }
+      page.contents = prependYAML(page.contents, {
+        // TODO: figure out a way to point to the source files?
+        editLink: false,
+      })
     }
   )
 
@@ -111,6 +68,9 @@ exports.createTypeDocApp = function createTypeDocApp(config = {}) {
     }
     await app.bootstrapWithPlugins(options)
     const project = app.convert()
+    if (!project) {
+      throw new Error('No project')
+    }
     return handleProject(project)
   }
 
@@ -161,7 +121,7 @@ async function exists(path) {
 /**
  * Prepends YAML block to a string
  * @param {string} contents - string to prepend to
- * @param {FrontMattersVars} vars - object of required front matter variables
+ * @param {FrontMatterVars} vars - object of required front matter variables
  */
 function prependYAML(contents, vars) {
   return contents