INNER CODE UNIT · JavaScript

fmSlugMatch

rockbenben/ChatGPT-Shortcut · plugin-gen-geo.js:183

        const fmSlugMatch = content.match(/^slug:\s*(.*)$/m);
        let slug;
        if (fmSlugMatch) {
          const raw = fmSlugMatch[1].replace(/^['"]|['"]$/g, "").trim();
          if (raw.startsWith("/")) {
            // 绝对 slug:相对 docs 路由根
            slug = raw.replace(/^\/+/, "").replace(/\/+$/, "");
          } else {
            // 相对 slug:替换所在目录下的最后一段
            const dir = relativePath.replace(/\\/g, "/").replace(/\/?[^/]*$/, "");
            slug = `${dir ? dir + "/" : ""}${raw}`.replace(/\/+$/, "");
          }
        } else {
          slug = relativePath
            .replace(/\\/g, "/")
            .replace(/\.md$/, "")
            .replace(/\/(index|readme)$/i, "")
            .replace(/^(index|readme)$/i, "");

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…