From b9fea874fa104ea5a9e2fe095232caa36f7415f7 Mon Sep 17 00:00:00 2001 From: Thang Bui Quang <89576896+thangbuiq@users.noreply.github.com> Date: Sat, 17 Feb 2024 12:59:28 +0000 Subject: [PATCH] feat: add algolia search with crawl actions --- .github/workflows/auto_dependabot.yml | 6 ++++- .github/workflows/pages.yml | 16 ++++++++++++ .gitignore | 2 ++ config.json | 36 +++++++++++++++++++++++++++ docusaurus.config.js | 16 ++++++------ package.json | 2 +- src/css/custom.css | 6 +---- 7 files changed, 68 insertions(+), 16 deletions(-) create mode 100644 config.json diff --git a/.github/workflows/auto_dependabot.yml b/.github/workflows/auto_dependabot.yml index c579d62..8b3ac2b 100644 --- a/.github/workflows/auto_dependabot.yml +++ b/.github/workflows/auto_dependabot.yml @@ -34,7 +34,11 @@ jobs: curl -X PUT \ -H "Authorization: Bearer ${{ secrets.TOKEN_GITHUB }}" \ -H "Accept: application/vnd.github.v3+json" \ - "https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/merge?merge_method=squash" + curl -X PUT \ + -H "Authorization: Bearer ${{ secrets.TOKEN_GITHUB }}" \ + -H "Accept: application/vnd.github.v3+json" \ + -d '{"merge_method": "squash"}' \ + "https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/merge" env: USER_NAME: ubunchuu[bot] USER_EMAIL: 159746302+ubunchuu-admin@users.noreply.github.com diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml index 7007cc0..044f24d 100644 --- a/.github/workflows/pages.yml +++ b/.github/workflows/pages.yml @@ -117,3 +117,19 @@ jobs: - name: Deploy to GitHub Pages id: deployment uses: actions/deploy-pages@v4 + + - name: Setup Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Install jq + uses: dcarbone/install-jq-action@v2.1.0 + + - name: Input Algolia secret into .env + run: | + touch .env + echo "API_KEY=${{ secrets.ALGOLIA_API_KEY }}" >> .env + echo "APPLICATION_ID=${{ secrets.ALGOLIA_APP_ID }}" >> .env + + - name: Crawling the deployed website using Algolia DocSearch + run: | + docker run -it --env-file=.env -e "CONFIG=$(cat config.json | jq -r tostring)" algolia/docsearch-scraper diff --git a/.gitignore b/.gitignore index d8966b8..577e649 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +**/.env + # Dependencies /node_modules diff --git a/config.json b/config.json new file mode 100644 index 0000000..a968b7c --- /dev/null +++ b/config.json @@ -0,0 +1,36 @@ +{ + "index_name": "ubunchuu-truong-usio", + "sitemap_urls": ["https://ubunchuu-truong-us.github.io/sitemap.xml"], + "sitemap_alternate_links": true, + "stop_urls": ["/tests"], + "selectors": { + "lvl0": { + "selector": "(//ul[contains(@class,'menu__list')]//a[contains(@class, 'menu__link menu__link--sublist menu__link--active')]/text() | //nav[contains(@class, 'navbar')]//a[contains(@class, 'navbar__link--active')]/text())[last()]", + "type": "xpath", + "global": true, + "default_value": "Documentation" + }, + "lvl1": "header h1", + "lvl2": "article h2", + "lvl3": "article h3", + "lvl4": "article h4", + "lvl5": "article h5, article td:first-child", + "lvl6": "article h6", + "text": "article p, article li, article td:last-child" + }, + "strip_chars": " .,;:#", + "custom_settings": { + "separatorsToIndex": "_", + "attributesForFaceting": ["language", "version", "type", "docusaurus_tag"], + "attributesToRetrieve": [ + "hierarchy", + "content", + "anchor", + "url", + "url_without_anchor", + "type" + ] + }, + "conversation_id": ["833762294"], + "nb_hits": 46250 +} diff --git a/docusaurus.config.js b/docusaurus.config.js index 0425264..0406147 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -27,15 +27,6 @@ const config = { // If you aren't using GitHub pages, you don't need these. organizationName: 'ubunchuu-truong-us', // Usually your GitHub org/user name. projectName: 'ubunchuu-truong-us.github.io', // Usually your repo name. - // Search bar config - themes: [ - [ - require.resolve('@easyops-cn/docusaurus-search-local'), - { - hashed: true, - }, - ], - ], onBrokenLinks: 'throw', onBrokenMarkdownLinks: 'warn', @@ -68,6 +59,13 @@ const config = { themeConfig: /** @type {import('@docusaurus/preset-classic').ThemeConfig} */ ({ + // Algolia DocSearch search integration + algolia: { + contextualSearch: true, + apiKey: '0a9bc2d53144bd55ed0ba248b6876331', // Public API Key (safe to share) + appId: '7VSRZ5ZBII', // Provided by Algolia to identify your application + indexName: 'ubunchuu-truong-usio', // Name of the index you want to target + }, // Replace with your project's social card image: 'img/docusaurus-social-card.jpg', navbar: { diff --git a/package.json b/package.json index 1926e3b..a3c4670 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "dependencies": { "@docusaurus/core": "3.1.1", "@docusaurus/preset-classic": "3.1.1", - "@easyops-cn/docusaurus-search-local": "^0.40.1", + "@docusaurus/theme-search-algolia": "^3.1.1", "@mdx-js/react": "^3.0.1", "clsx": "^2.0.0", "prism-react-renderer": "^2.3.0", diff --git a/src/css/custom.css b/src/css/custom.css index 1ab8d21..a9d7f0f 100644 --- a/src/css/custom.css +++ b/src/css/custom.css @@ -5,11 +5,7 @@ */ @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&display=swap'); -@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono&display=swap'); - -/* code span { - font-family: 'JetBrains Mono', monospace !important; -} */ +@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;700&display=swap'); /* You can override the default Infima variables here. */ :root {