Skip to content

Commit

Permalink
Merge pull request #19 from onflow/nialexsan/search
Browse files Browse the repository at this point in the history
  • Loading branch information
turbolent authored Nov 21, 2023
2 parents 8b2c8c4 + 30f499f commit 6a2e179
Show file tree
Hide file tree
Showing 9 changed files with 347 additions and 13 deletions.
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

TYPESENSE_NODE="<TYPESENSE_NODE>"
TYPESENSE_SEARCH_ONLY_API_KEY="<TYPESENSE_SEARCH_ONLY_API_KEY>"
TYPESENSE_ADMIN_API_KEY="<TYPESENSE_ADMIN_API_KEY>"

MIXPANEL_PROJECT_TOKEN="<MIXPANEL_PROJECT_TOKEN>"
47 changes: 47 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Test build & Scrape

on:
workflow_dispatch:
push:
branches:
- main

env:
TYPESENSE_NODE: ${{ vars.TYPESENSE_NODE }}
TYPESENSE_ADMIN_API_KEY: ${{ secrets.TYPESENSE_ADMIN_API_KEY }}

jobs:
build:
name: Test build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
node-version: 18
cache: npm

- name: Install dependencies
run: npm i

- name: Build website
run: npm run build

- name: Run DocSearch Scraper
uses: celsiusnarhwal/typesense-scraper@v2
with:
# The secret containing your Typesense API key. Required.
api-key: ${{ env.TYPESENSE_ADMIN_API_KEY }}

# The hostname or IP address of your Typesense server. Required.
host: ${{ env.TYPESENSE_NODE }}

# The port on which your Typesense server is listening. Optional. Default: 8108.
port: 443

# The protocol to use when connecting to your Typesense server. Optional. Default: http.
protocol: https

# The path to your DocSearch config file. Optional. Default: docsearch.config.json.
config: docsearch.config.json
33 changes: 33 additions & 0 deletions .github/workflows/scrape.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: DocSearch Scraper

on:
workflow_dispatch:

env:
TYPESENSE_NODE: ${{ vars.TYPESENSE_NODE }}
TYPESENSE_ADMIN_API_KEY: ${{secrets.TYPESENSE_ADMIN_API_KEY}}

jobs:
crawl:
name: Crawl Pages
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Run DocSearch Scraper
uses: celsiusnarhwal/typesense-scraper@v2
with:
# The secret containing your Typesense API key. Required.
api-key: ${{ env.TYPESENSE_ADMIN_API_KEY }}

# The hostname or IP address of your Typesense server. Required.
host: ${{ env.TYPESENSE_NODE }}

# The port on which your Typesense server is listening. Optional. Default: 8108.
port: 443

# The protocol to use when connecting to your Typesense server. Optional. Default: http.
protocol: https

# The path to your DocSearch config file. Optional. Default: docsearch.config.json.
config: docsearch.config.json
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*

.env
46 changes: 46 additions & 0 deletions docsearch.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"index_name": "cadence_lang",
"start_urls": [
"https://cadence-lang.org/"
],
"sitemap_urls": [
"https://cadence-lang.org/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": "article h1, 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"
]
}
}
29 changes: 28 additions & 1 deletion docusaurus.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
// @ts-check
// Note: type annotations allow type checking and IDEs autocompletion

require('dotenv').config();
const lightCodeTheme = require('prism-react-renderer/themes/github');
const darkCodeTheme = require('prism-react-renderer/themes/dracula');

const theme = require('shiki/themes/nord.json');
const { remarkCodeHike } = require('@code-hike/mdx');

const hasTypesense =
process.env.TYPESENSE_NODE && process.env.TYPESENSE_SEARCH_ONLY_API_KEY;

/** @type {import('@docusaurus/types').Config} */
const config = {
title: 'Cadence',
Expand Down Expand Up @@ -82,6 +85,8 @@ const config = {
],
],

themes: [hasTypesense && 'docusaurus-theme-search-typesense'].filter(Boolean),

themeConfig:
/** @type {import('@docusaurus/preset-classic').ThemeConfig} */
({
Expand Down Expand Up @@ -169,6 +174,28 @@ const config = {
theme: lightCodeTheme,
darkTheme: darkCodeTheme,
},
typesense: hasTypesense && {
// Replace this with the name of your index/collection.
// It should match the "index_name" entry in the scraper's "config.json" file.
typesenseCollectionName: 'cadence_lang',

typesenseServerConfig: {
nodes: [
{
host: process.env.TYPESENSE_NODE,
port: 443,
protocol: 'https',
},
],
apiKey: process.env.TYPESENSE_SEARCH_ONLY_API_KEY,
},

// Optional: Typesense search parameters: https://typesense.org/docs/0.24.0/api/search.html#search-parameters
typesenseSearchParameters: {},

// Optional
contextualSearch: true,
},
}),
};

Expand Down
161 changes: 161 additions & 0 deletions package-lock.json

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

Loading

1 comment on commit 6a2e179

@vercel
Copy link

@vercel vercel bot commented on 6a2e179 Nov 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

cadence-lang-docs – ./

cadence-lang-docs.vercel.app
cadence-lang-docs-git-main-onflow.vercel.app
cadence-lang-docs-onflow.vercel.app

Please sign in to comment.