diff --git a/.github/workflows/scrape.yml b/.github/workflows/scrape.yml index 4838b7391d..5c01d6a300 100644 --- a/.github/workflows/scrape.yml +++ b/.github/workflows/scrape.yml @@ -7,6 +7,7 @@ on: paths: - '.github/workflows/scrape.yml' - 'docs/**' + workflow_dispatch: ~ jobs: scrape-docs: @@ -14,10 +15,16 @@ jobs: steps: - name: Checkout uses: actions/checkout@v3 + - name: Use Node.js v16 + uses: actions/setup-node@v3 + with: + node-version: 16 + cache: 'yarn' - name: Pull image run: docker pull getmeili/docs-scraper - name: Wait for Netlify to finish run: sleep 3m + if: github.event_name == 'push' - name: Run docs-scraper env: HOST_URL: ${{ secrets.MEILISEARCH_HOST_URL }} @@ -29,3 +36,14 @@ jobs: -e MEILISEARCH_API_KEY=$API_KEY \ -v $CONFIG_FILE_PATH:/docs-scraper/config.json \ getmeili/docs-scraper pipenv run ./docs_scraper config.json + - name: Update meilisearch settings + uses: actions/github-script@v6 + env: + HOST_URL: ${{ secrets.MEILISEARCH_HOST_URL }} + API_KEY: ${{ secrets.MEILISEARCH_API_KEY }} + with: + script: | + const meilisearchHost = process.env.HOST_URL + const meilisearchApiKey = process.env.API_KEY + const script = require(`${process.env.GITHUB_WORKSPACE}/scripts/docs-scraper/settings.js`) + await script({ core }, meilisearchHost, meilisearchApiKey) diff --git a/package.json b/package.json index ee0ac679e0..58a21cbca3 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ "eslint-plugin-yml": "1.1.0", "fs-extra": "10.1.0", "jest": "29.0.1", + "meilisearch": "0.27.0", "mockdate": "3.0.5", "nock": "13.2.9", "nodemon": "2.0.19", diff --git a/scripts/docs-scraper/settings.js b/scripts/docs-scraper/settings.js new file mode 100644 index 0000000000..3b96e19521 --- /dev/null +++ b/scripts/docs-scraper/settings.js @@ -0,0 +1,55 @@ +const { MeiliSearch } = require('meilisearch'); + +module.exports = async ({ core }, host, apiKey) => { + const client = new MeiliSearch({ + host, + apiKey, + }); + core.info('Updating displayed attributes'); + core.info( + await client + .index('rsshub') + .updateDisplayedAttributes([ + 'hierarchy_radio_lvl1', + 'hierarchy_radio_lvl2', + 'hierarchy_radio_lvl3', + 'hierarchy_radio_lvl4', + 'hierarchy_radio_lvl5', + 'hierarchy_lvl0', + 'hierarchy_lvl1', + 'hierarchy_lvl2', + 'hierarchy_lvl3', + 'hierarchy_lvl4', + 'hierarchy_lvl5', + 'hierarchy_lvl6', + 'anchor', + 'url', + 'content', + ]) + ); + + core.info('Updating searchable attributes'); + core.info( + await client + .index('rsshub') + .updateSearchableAttributes([ + 'hierarchy_radio_lvl1', + 'hierarchy_radio_lvl2', + 'hierarchy_radio_lvl3', + 'hierarchy_radio_lvl4', + 'hierarchy_radio_lvl5', + 'hierarchy_lvl0', + 'hierarchy_lvl1', + 'hierarchy_lvl2', + 'hierarchy_lvl3', + 'hierarchy_lvl4', + 'hierarchy_lvl5', + 'hierarchy_lvl6', + 'anchor', + 'content', + ]) + ); + + core.info('Updating sortable attributes'); + core.info(await client.index('rsshub').updateSortableAttributes(['anchor'])); +}; diff --git a/yarn.lock b/yarn.lock index c0711de80d..a79a50f651 100644 --- a/yarn.lock +++ b/yarn.lock @@ -9590,7 +9590,7 @@ media-typer@0.3.0: resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748" integrity sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ== -meilisearch@^0.27.0: +meilisearch@0.27.0, meilisearch@^0.27.0: version "0.27.0" resolved "https://registry.yarnpkg.com/meilisearch/-/meilisearch-0.27.0.tgz#8bd57ddb77b975f93e054cb977b951c488ece297" integrity sha512-kZOZFIuSO7c6xRf+Y2/9/h6A9pl0sCl/G44X4KuaSwxGbruOZPhmxbeVEgLHBv4pUFvQ56rNVTA/2d/5GCU1YA==