pengzhanbo / vuepress-theme-plume

Vuepress Theme. A simple, feature-rich, document & blog
https://theme-plume.vuejs.press
MIT License
50 stars 11 forks source link

如何使用 Algolia DocSearch 索引本主题 #27

Closed huankong233 closed 6 months ago

huankong233 commented 6 months ago

请教一下如何使用 Algolia DocSearch 索引本主题

以下为我的配置文件,records 一直都是空的 🤔

new Crawler({
  rateLimit: 8,
  maxDepth: 10,
  startUrls: ["https://blog.huankong.top/"],
  renderJavaScript: false,
  sitemaps: ["https://blog.huankong.top/sitemap.xml"],
  ignoreCanonicalTo: false,
  discoveryPatterns: ["https://blog.huankong.top/**"],
  schedule: "at 02:00 every 1 day",
  actions: [
    {
      indexName: "huankong",
      pathsToMatch: ["https://blog.huankong.top/**"],
      recordExtractor: ({ $, helpers }) => {
        return helpers.docsearch({
          recordProps: {
            lvl0: {
              selectors: ".sidebar-item.is-active",
              defaultValue: "Documentation",
            },
            lvl1: ".content-container h1",
            lvl2: ".content-container h2",
            lvl3: ".content-container h3",
            lvl4: ".content-container h4",
            lvl5: ".content-container h5",
            lvl6: ".content-container h5",
            content: ".content-container p, .content-container li",
          },
          indexHeadings: true,
        });
      },
    },
  ],
  initialIndexSettings: {
    huankong: {
      attributesForFaceting: ["type", "lang", "language", "version"],
      attributesToRetrieve: [
        "hierarchy",
        "content",
        "anchor",
        "url",
        "url_without_anchor",
        "type",
      ],
      attributesToHighlight: ["hierarchy", "hierarchy_camel", "content"],
      attributesToSnippet: ["content:10"],
      camelCaseAttributes: ["hierarchy", "hierarchy_radio", "content"],
      searchableAttributes: [
        "unordered(hierarchy_radio_camel.lvl0)",
        "unordered(hierarchy_radio.lvl0)",
        "unordered(hierarchy_radio_camel.lvl1)",
        "unordered(hierarchy_radio.lvl1)",
        "unordered(hierarchy_radio_camel.lvl2)",
        "unordered(hierarchy_radio.lvl2)",
        "unordered(hierarchy_radio_camel.lvl3)",
        "unordered(hierarchy_radio.lvl3)",
        "unordered(hierarchy_radio_camel.lvl4)",
        "unordered(hierarchy_radio.lvl4)",
        "unordered(hierarchy_radio_camel.lvl5)",
        "unordered(hierarchy_radio.lvl5)",
        "unordered(hierarchy_radio_camel.lvl6)",
        "unordered(hierarchy_radio.lvl6)",
        "unordered(hierarchy_camel.lvl0)",
        "unordered(hierarchy.lvl0)",
        "unordered(hierarchy_camel.lvl1)",
        "unordered(hierarchy.lvl1)",
        "unordered(hierarchy_camel.lvl2)",
        "unordered(hierarchy.lvl2)",
        "unordered(hierarchy_camel.lvl3)",
        "unordered(hierarchy.lvl3)",
        "unordered(hierarchy_camel.lvl4)",
        "unordered(hierarchy.lvl4)",
        "unordered(hierarchy_camel.lvl5)",
        "unordered(hierarchy.lvl5)",
        "unordered(hierarchy_camel.lvl6)",
        "unordered(hierarchy.lvl6)",
        "content",
      ],
      distinct: true,
      attributeForDistinct: "url",
      customRanking: [
        "desc(weight.pageRank)",
        "desc(weight.level)",
        "asc(weight.position)",
      ],
      ranking: [
        "words",
        "filters",
        "typo",
        "attribute",
        "proximity",
        "exact",
        "custom",
      ],
      highlightPreTag: '<span class="algolia-docsearch-suggestion--highlight">',
      highlightPostTag: "</span>",
      minWordSizefor1Typo: 3,
      minWordSizefor2Typos: 7,
      allowTyposOnNumericTokens: false,
      minProximity: 1,
      ignorePlurals: true,
      advancedSyntax: true,
      attributeCriteriaComputedByMinProximity: true,
      removeWordsIfNoResults: "allOptional",
    },
  },
  appId: "U198Y5GBFG",
  apiKey: "xxxxx",
});
huankong233 commented 6 months ago

现在最新的那个编译好像还会报错 🤔

[Vue warn]: Invalid watch source:  { open: false } A watch source can only be a getter/effect function, a ref, a reactive object, or an array of these types.
pengzhanbo commented 6 months ago
        recordProps: {
            lvl0: {
              selectors: ".sidebar-item.is-active",
              defaultValue: "Documentation",
            },
            lvl1: ".content-container h1",
            lvl2: ".content-container h2",
            lvl3: ".content-container h3",
            lvl4: ".content-container h4",
            lvl5: ".content-container h5",
            lvl6: ".content-container h5",
            content: ".content-container p, .content-container li",
          },

这部分的内容中, 替换内容为

      recordProps: {
            lvl1: ".plume-theme-content h1",
            content: ".plume-theme-content p, .plume-theme-content li",
            lvl0: {
              selectors: "p.sidebar-heading.active",
              defaultValue: "Documentation",
            },
            lvl2: ".plume-theme-content h2",
            lvl3: ".plume-theme-content h3",
            lvl4: ".plume-theme-content h4",
            lvl5: ".plume-theme-content h5",
            lang: "",
            tags: {
              defaultValue: ["v2"],
            },
          },

Algolia DocSearch 是通过在线爬虫抓取网站内容,然后再生成 搜索索引数据库的,首先需要确保 站点已部署并且可访问。 默认情况下它会定时自动爬取数据,也可以在 Overview 选项卡页面的右上角,点击 restart clawling 手动触发爬取。

huankong233 commented 6 months ago
        recordProps: {
            lvl0: {
              selectors: ".sidebar-item.is-active",
              defaultValue: "Documentation",
            },
            lvl1: ".content-container h1",
            lvl2: ".content-container h2",
            lvl3: ".content-container h3",
            lvl4: ".content-container h4",
            lvl5: ".content-container h5",
            lvl6: ".content-container h5",
            content: ".content-container p, .content-container li",
          },

这部分的内容中, 替换内容为

      recordProps: {
            lvl1: ".plume-theme-content h1",
            content: ".plume-theme-content p, .plume-theme-content li",
            lvl0: {
              selectors: "p.sidebar-heading.active",
              defaultValue: "Documentation",
            },
            lvl2: ".plume-theme-content h2",
            lvl3: ".plume-theme-content h3",
            lvl4: ".plume-theme-content h4",
            lvl5: ".plume-theme-content h5",
            lang: "",
            tags: {
              defaultValue: ["v2"],
            },
          },

Algolia DocSearch 是通过在线爬虫抓取网站内容,然后再生成 搜索索引数据库的,首先需要确保 站点已部署并且可访问。 默认情况下它会定时自动爬取数据,也可以在 Overview 选项卡页面的右上角,点击 restart clawling 手动触发爬取。

好的,我尝试一下

pengzhanbo commented 6 months ago

现在最新的那个编译好像还会报错 🤔

[Vue warn]: Invalid watch source:  { open: false } A watch source can only be a getter/effect function, a ref, a reactive object, or an array of these types.

最近我在频繁更新调整主题,有些细节和警告可能会稍有疏漏

huankong233 commented 6 months ago
        recordProps: {
            lvl0: {
              selectors: ".sidebar-item.is-active",
              defaultValue: "Documentation",
            },
            lvl1: ".content-container h1",
            lvl2: ".content-container h2",
            lvl3: ".content-container h3",
            lvl4: ".content-container h4",
            lvl5: ".content-container h5",
            lvl6: ".content-container h5",
            content: ".content-container p, .content-container li",
          },

这部分的内容中, 替换内容为

      recordProps: {
            lvl1: ".plume-theme-content h1",
            content: ".plume-theme-content p, .plume-theme-content li",
            lvl0: {
              selectors: "p.sidebar-heading.active",
              defaultValue: "Documentation",
            },
            lvl2: ".plume-theme-content h2",
            lvl3: ".plume-theme-content h3",
            lvl4: ".plume-theme-content h4",
            lvl5: ".plume-theme-content h5",
            lang: "",
            tags: {
              defaultValue: ["v2"],
            },
          },

Algolia DocSearch 是通过在线爬虫抓取网站内容,然后再生成 搜索索引数据库的,首先需要确保 站点已部署并且可访问。 默认情况下它会定时自动爬取数据,也可以在 Overview 选项卡页面的右上角,点击 restart clawling 手动触发爬取。

好的,我尝试一下

好像不行(,我已经部署成功而且可以访问了啊,奇怪了

pengzhanbo commented 6 months ago

我看配置的其他部分没有什么问题, 或许检查下你的 Index 名是否正确, 是否是配置了 index prefix 导致了 名称没有匹配等。

huankong233 commented 6 months ago

我看配置的其他部分没有什么问题, 或许检查下你的 Index 名是否正确, 是否是配置了 index prefix 导致了 名称没有匹配等。

image

是huankong啊🤔🤔🤔

pengzhanbo commented 6 months ago

看起来你不是访问的这个地址: https://crawler.algolia.com/admin/crawlers/

huankong233 commented 6 months ago

我看配置的其他部分没有什么问题, 或许检查下你的 Index 名是否正确, 是否是配置了 index prefix 导致了 名称没有匹配等。

image

是huankong啊🤔🤔🤔

image

🤔🤔🤔

huankong233 commented 6 months ago

看起来你不是访问的这个地址: https://crawler.algolia.com/admin/crawlers/

image

一样都是huankong

pengzhanbo commented 6 months ago

.plume-content,笑死,我的配置也忘改了。

huankong233 commented 6 months ago

.plume-content,笑死,我的配置也忘改了。

我就说不对嘛 😂

huankong233 commented 6 months ago

.plume-content,笑死,我的配置也忘改了。

我就说不对嘛 😂

但是记录还是空的()

pengzhanbo commented 6 months ago
new Crawler({
  rateLimit: 8,
  startUrls: ["https://pengzhanbo.cn/"],
  renderJavaScript: false,
  sitemaps: ["https://pengzhanbo.cn//sitemap.xml"],
  ignoreCanonicalTo: true,
  discoveryPatterns: ["https://pengzhanbo.cn/**"],
  schedule: "at 02:00 every 1 day",
  actions: [
    {
      indexName: "pengzhanbo",
      pathsToMatch: ["https://pengzhanbo.cn/**"],
      recordExtractor: ({ helpers }) => {
        return helpers.docsearch({
          recordProps: {
            lvl1: ".plume-content h1",
            content: ".plume-content p, .plume-content li",
            lvl0: {
              selectors: "p.sidebar-heading.active",
              defaultValue: "Documentation",
            },
            lvl2: ".plume-content h2",
            lvl3: ".plume-content h3",
            lvl4: ".plume-content h4",
            lvl5: ".plume-content h5",
            lang: "",
            tags: {
              defaultValue: ["v2"],
            },
          },
          aggregateContent: true,
          recordVersion: "v3",
        });
      },
    },
  ],
  initialIndexSettings: {
    pengzhanbo: {
      attributesForFaceting: ["type", "lang", "language", "version"],
      attributesToRetrieve: [
        "hierarchy",
        "content",
        "anchor",
        "url",
        "url_without_anchor",
        "type",
      ],
      attributesToHighlight: ["hierarchy", "hierarchy_camel", "content"],
      attributesToSnippet: ["content:10"],
      camelCaseAttributes: ["hierarchy", "hierarchy_radio", "content"],
      searchableAttributes: [
        "unordered(hierarchy_radio_camel.lvl0)",
        "unordered(hierarchy_radio.lvl0)",
        "unordered(hierarchy_radio_camel.lvl1)",
        "unordered(hierarchy_radio.lvl1)",
        "unordered(hierarchy_radio_camel.lvl2)",
        "unordered(hierarchy_radio.lvl2)",
        "unordered(hierarchy_radio_camel.lvl3)",
        "unordered(hierarchy_radio.lvl3)",
        "unordered(hierarchy_radio_camel.lvl4)",
        "unordered(hierarchy_radio.lvl4)",
        "unordered(hierarchy_radio_camel.lvl5)",
        "unordered(hierarchy_radio.lvl5)",
        "unordered(hierarchy_radio_camel.lvl6)",
        "unordered(hierarchy_radio.lvl6)",
        "unordered(hierarchy_camel.lvl0)",
        "unordered(hierarchy.lvl0)",
        "unordered(hierarchy_camel.lvl1)",
        "unordered(hierarchy.lvl1)",
        "unordered(hierarchy_camel.lvl2)",
        "unordered(hierarchy.lvl2)",
        "unordered(hierarchy_camel.lvl3)",
        "unordered(hierarchy.lvl3)",
        "unordered(hierarchy_camel.lvl4)",
        "unordered(hierarchy.lvl4)",
        "unordered(hierarchy_camel.lvl5)",
        "unordered(hierarchy.lvl5)",
        "unordered(hierarchy_camel.lvl6)",
        "unordered(hierarchy.lvl6)",
        "content",
      ],
      distinct: true,
      attributeForDistinct: "url",
      customRanking: [
        "desc(weight.pageRank)",
        "desc(weight.level)",
        "asc(weight.position)",
      ],
      ranking: [
        "words",
        "filters",
        "typo",
        "attribute",
        "proximity",
        "exact",
        "custom",
      ],
      highlightPreTag: '<span class="algolia-docsearch-suggestion--highlight">',
      highlightPostTag: "</span>",
      minWordSizefor1Typo: 3,
      minWordSizefor2Typos: 7,
      allowTyposOnNumericTokens: false,
      minProximity: 1,
      ignorePlurals: true,
      advancedSyntax: true,
      attributeCriteriaComputedByMinProximity: true,
      removeWordsIfNoResults: "allOptional",
    },
  },
  appId: "xxx",
  apiKey: "xxxx",
});

这是我目前的配置

pengzhanbo commented 6 months ago

image 试试在 run test 中 访问下你的站点,看看是否获取到的内容是最新的。 也有可能是DNS的影响, algolia 服务器访问到旧资源

huankong233 commented 6 months ago

image 试试在 run test 中 访问下你的站点,看看是否获取到的内容是最新的。 也有可能是DNS的影响, algolia 服务器访问到旧资源

image

然后替换了一下你的那个配置,报错了

image

huankong233 commented 6 months ago

image 试试在 run test 中 访问下你的站点,看看是否获取到的内容是最新的。 也有可能是DNS的影响, algolia 服务器访问到旧资源

image

然后替换了一下你的那个配置,报错了

image

替换了之后,依旧是空 (

pengzhanbo commented 6 months ago

image 一般来说替换这部分就可以了。

pengzhanbo commented 6 months ago

missing records 说明了 algolia 没有访问到页面,可能问题出在这里了。

huankong233 commented 6 months ago

missing records 说明了 algolia 没有访问到页面,可能问题出在这里了。

然后我重新索引了一下还是没有,要不我把号给你😂

pengzhanbo commented 6 months ago

好,你加我 QQ 吧。

huankong233 commented 6 months ago

确认是 bug 并已修复