Skip to content

feat: integrate meilisearch #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions .github/docs-scraper/docs.rsshub.app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"index_uid": "rsshub-staging",
"sitemap_urls": ["https://docs.rsshub.app/sitemap.xml"],
"start_urls": ["https://docs.rsshub.app"],
"selectors": {
"lvl0": {
"selector": "",
"global": true,
"default_value": "Routes"
},
"lvl1": ".content h1",
"lvl2": ".content h2",
"lvl3": ".content h3",
"lvl4": ".content h4",
"lvl5": ".content h5",
"text": ".content p, .content .params, .content table, .content p code"
},
"strip_chars": " .,;:#",
"scrap_start_urls": false,
"min_indexed_level": 1,
"js_render": false,
"js_wait": 2,
"custom_settings": {
"displayedAttributes": [
"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"
],
"searchableAttributes": [
"hierarchy_lvl2",
"hierarchy_lvl3",
"hierarchy_lvl4",
"anchor",
"content",
"hierarchy_lvl5",
"hierarchy_lvl1"
],
"sortableAttributes": ["anchor"]
},
"selectors_exclude": [".badge", ".author", ".tip"]
}
54 changes: 54 additions & 0 deletions .github/workflows/docs-search-index.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Update meilisearch index

on:
push:
branches:
- master
paths:
- '.github/workflows/docs-search-index.yml'
- '.github/docs-scraper/docs.rsshub.app.json'
- 'src/**'
workflow_dispatch: {}
schedule:
- cron: '44 1 * * 1'

permissions:
contents: read

concurrency:
group: docs-search-index
cancel-in-progress: true

jobs:
scrape-docs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Pull image
run: docker pull getmeili/docs-scraper
- name: Wait for Netlify to finish
if: github.event_name == 'push' && github.run_attempt == 1
run: sleep 1m
- name: Run docs-scraper
timeout-minutes: 30
env:
HOST_URL: ${{ vars.MEILISEARCH_HOST_URL }}
API_KEY: ${{ secrets.MEILISEARCH_API_KEY }}
CONFIG_FILE_PATH: ${{ github.workspace }}/.github/docs-scraper/docs.rsshub.app.json
run: |
docker run -t --rm \
-e MEILISEARCH_HOST_URL=$HOST_URL \
-e MEILISEARCH_API_KEY=$API_KEY \
-v $CONFIG_FILE_PATH:/docs-scraper/config.json \
getmeili/docs-scraper pipenv run ./docs_scraper config.json
- name: Swap index
env:
HOST_URL: ${{ vars.MEILISEARCH_HOST_URL }}
API_KEY: ${{ secrets.MEILISEARCH_API_KEY }}
run: |
curl \
-X POST $HOST_URL/swap-indexes \
-H "Authorization: Bearer $API_KEY" \
-H 'Content-Type: application/json' \
-d '[{"indexes":["rsshub","rsshub-staging"]}]'
20 changes: 3 additions & 17 deletions .vitepress/config/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export const shared = defineConfig({
dark: 'github-dark',
},
},
sitemap: {
hostname: 'https://docs.rsshub.app',
},

head: [
['meta', { property: 'og:image', content: 'https://docs.rsshub.app/logo.png' }],
Expand All @@ -57,23 +60,6 @@ export const shared = defineConfig({
outline: {
level: [2, 3],
},
search: {
provider: 'local',
options: {
miniSearch: {
options: {
extractField: (document, fieldName) => {
if (fieldName !== 'text' || document.id.includes('/routes/')) {
return document[fieldName]
}
},
},
searchOptions: {
boost: { title: 1, text: 0.1, titles: 1 }
}
}
}
},

// https://vitepress.dev/reference/default-theme-config
nav: [
Expand Down
25 changes: 24 additions & 1 deletion .vitepress/theme/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// https://vitepress.dev/guide/custom-theme
import { h } from 'vue'
import { h, onMounted } from 'vue'
import type { Theme } from 'vitepress'
import DefaultTheme from 'vitepress/theme'
import "meilisearch-docsearch/css";
import './style.css'
import Route from './components/Route.vue'
import Site from './components/Site.vue'
Expand All @@ -10,9 +11,31 @@ import InstanceList from './components/InstanceList.vue'

export default {
extends: DefaultTheme,
setup() {
onMounted(() => {
// For SSR Compatibility https://vitepress.dev/guide/ssr-compat#ssr-compatibility
import('meilisearch-docsearch').then((docsearch) => {
docsearch.default({
container: "#docsearch",
host: "https://meilisearch.rsshub.app",
apiKey: "375c36cd9573a2c1d1e536214158c37120fdd0ba6cd8829f7a848e940cc22245",
indexUid: "rsshub",
});
})
})
},
Layout: () => {
return h(DefaultTheme.Layout, null, {
// https://vitepress.dev/guide/extending-default-theme#layout-slots
'nav-bar-content-before': () => h(
'span',
{ id: 'content-before' },
[
h('span', {
id: 'docsearch'
}),
]
),
})
},
enhanceApp({ app, router, siteData }) {
Expand Down
21 changes: 17 additions & 4 deletions .vitepress/theme/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,26 @@
}

/**
* Component: Algolia
* Component: meilisearch
* -------------------------------------------------------------------------- */

.DocSearch {
--docsearch-primary-color: var(--vp-c-brand-1) !important;
:root {
--docsearch-primary-color: var(--vp-c-brand-2);
}

#content-before {
display: flex;
justify-content: space-between;
}

#docsearch {
margin: auto 1em;
}


/**
* Component: Other
* -------------------------------------------------------------------------- */
:root {
--vp-c-text-1: #000;
--vp-c-text-2: #454545;
Expand Down Expand Up @@ -189,4 +202,4 @@

img {
display: inline-block;
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"type": "module",
"devDependencies": {
"markdown-it": "14.0.0",
"meilisearch-docsearch": "0.6.0",
"vitepress": "1.0.0-rc.45",
"vue": "3.4.21"
},
Expand Down
67 changes: 67 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ layout: home
hero:
name: "RSSHub"
text: "Everything is RSSible"
tagline: 🧡 Generate a RSS/Atom/JSON feed from anything.
tagline: 🧡 Generate an RSS/Atom/JSON feed from anything.
image:
src: /logo.png
alt: RSSHub
Expand Down