Skip to content
Draft
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
6 changes: 6 additions & 0 deletions source/_static/css/homepage-v1.css

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

2 changes: 1 addition & 1 deletion source/_static/css/homepage-v1.css.map

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

1 change: 1 addition & 0 deletions source/_static/js/myscript-v1.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ $(document).ready(function () {
// Function to set the custom theme attribute based on the current theme
function setCustomTheme(theme) {
$('body').attr('data-custom-theme', theme);
$('html').attr('data-theme', theme);
}

// Check for a manually set theme
Expand Down
7 changes: 7 additions & 0 deletions source/_static/scss/partials/_sidebar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@
}
}

.DocSearch-Container {
margin-top: 55px;
}

.sidebar-search {
display: none;

border-radius: 4px;
border: 1px solid rgba(63, 67, 80, 0.16);
background: #FFF;
Expand All @@ -69,6 +75,7 @@ body:not([data-custom-theme="light"]) {
}

.sidebar-search-container:before {
height: 0px;
left: 32px;
z-index: 20;
background-color: currentColor;
Expand Down
33 changes: 28 additions & 5 deletions source/_templates/custom-nav.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<script>
window.addEventListener('load', () => {
const options = location.hostname === 'localhost' ? {
node: { host: 'localhost', port: '8108', protocol: 'http' },
apiKey: 'test_api_key',
} : {
node: { host: 'h0agqxfpir543j9lp-1.a1.typesense.net', port: '443', protocol: 'https' },
apiKey: 'ZOLa3xKupe9e7DRPhkv56g8VUoCygd00',
};

docsearch({
container: '.sidebar-search-container',
typesenseCollectionName: 'mm_product_docs',
typesenseServerConfig: {
nodes: [options.node],
apiKey: options.apiKey
},
typesenseSearchParams: {}
});
});
</script>

<div data-swiftype-index=false class="notification-bar sticky-top">
<div class="notification-bar__content">
<a class="notification-bar__close" data-ol-has-click-handler="">
Expand Down Expand Up @@ -69,7 +92,7 @@
<a href="https://mattermost.com/channels/">
Channels
</a>
</li>
</li>
<li class="sub-menu__links--single">
<a href="https://mattermost.com/playbooks/">
Playbooks
Expand Down Expand Up @@ -127,7 +150,7 @@
<a href="https://mattermost.com/enterprise/cloud/">
Cloud
</a>
</li>
</li>
</ul>
</div>
</div>
Expand Down Expand Up @@ -173,7 +196,7 @@
<a href="https://mattermost.com/solutions/use-cases/integrated-security-operations/">
Integrated Security Operations
</a>
</li>
</li>
<li class="sub-menu__links--single">
<a href="https://mattermost.com/solutions/use-cases/out-of-band-incident-response/">
Out-of-Band Incident Response
Expand Down Expand Up @@ -384,7 +407,7 @@
<div class="sub-menu__dev-link-col">
<p class="sub-menu__link-col-header sub-menu__link-col-header-space">Documentation</p>
<ul>

<li class="sub-menu__links--single">
<a href="https://academy.mattermost.com/">
Academy
Expand Down Expand Up @@ -429,7 +452,7 @@
<a href="https://mattermost.com/community/">
Join Community
</a>
</li>
</li>
<li class="sub-menu__links--single">
<a href="https://mattermost.com/contribute/">
Contribute
Expand Down
3 changes: 2 additions & 1 deletion source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4072,7 +4072,8 @@ def setup(_: Sphinx):
html_css_files = [
"css/mattermost-global.css",
"css/homepage-v1.css",
"css/compass-icons.css"
"css/compass-icons.css",
"https://cdn.jsdelivr.net/npm/[email protected]",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably want to bundle this, instead of serve from cdn, to be consistent with existing assets

]

# A list of JavaScript filenames. The entry must be a filename string or a tuple containing the filename string and the
Expand Down
16 changes: 16 additions & 0 deletions typesense/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from python:3

RUN apt-get update

WORKDIR /app

RUN pip3 install pipenv

COPY ./Pipfile .
COPY ./Pipfile.lock .

RUN pipenv install --dev

RUN mkdir -p build/html

COPY . .
34 changes: 34 additions & 0 deletions typesense/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Using Typesense for documentation search

We'll have 3 terminals open, and run the following in the first two:
- `make livehtml` - Run Sphinx docs server
- `cd typesense && docker compose up typesense` - Run Typesense server

After those are running, in the third terminal:
- `cd typesense && docker compose up scraper` - Run scraper to populate Typesense. The process will exit once complete


If you'd like to re-index the docs, you can run:

```sh
cd typesense
./scripts/reset-typesense-collection.sh # This will delete all existing documents in the collection. Typesense will de-duplicate docs naturally, but this forces it to remove metadata from previous runs that we may want to remove as we change the schema/filters.
docker compose up scraper
```

To export the index into a jsonl file, run:

```sh
cd typesense
./scripts/download-typesense-collection.sh
```

---

The scripts mentioned above support the following environment variables for configuration:

- `TYPESENSE_API_KEY` - Defaults to `test_api_key`
- `TYPESENSE_HOST` - Defaults to `http://localhost:8108`
- `TYPESENSE_HOSTNAME` - Defaults to `localhost`
- `TYPESENSE_PORT` - Defaults to `8108`
- `TYPESENSE_PROTOCOL` - Defaults to `http`
39 changes: 39 additions & 0 deletions typesense/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"index_name": "mm_product_docs",
"allowed_domains": [
"localhost",
"mattermost-docs-preview-pulls.s3-website-us-east-1.amazonaws.com"
],
"start_urls": [
{
"url": "http://localhost:8000",
"tags": []
}
],
"sitemap_urls": [
"http://localhost:8000/sitemap.xml"
],
"selectors": {
"default": {
"lvl0": "article h1",
"lvl1": "article h2",
"lvl2": "article h3",
"lvl3": "article h4",
"lvl4": "article h5",
"lvl5": "article h6",
"text": "article p, article li"
}
},
Comment on lines +7 to +26
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can add selectors for config settings, and section off user/admin docs. Below is an example from docsearch docs for sectioning off different content
https://docsearch.algolia.com/docs/legacy/config-file/#selectors_key-tailor-your-selectors

{
  "start_urls": [
    {
      "url": "http://www.example.com/docs/faq/",
      "selectors_key": "faq"
    },
    {
      "url": "http://www.example.com/docs/"
    }
  ],
  "selectors": {
    "default": {
      "lvl0": ".docs h1",
      "lvl1": ".docs h2",
      "lvl2": ".docs h3",
      "lvl3": ".docs h4",
      "lvl4": ".docs h5",
      "text": ".docs p, .docs li"
    },
    "faq": {
      "lvl0": ".faq h1",
      "lvl1": ".faq h2",
      "lvl2": ".faq h3",
      "lvl3": ".faq h4",
      "lvl4": ".faq h5",
      "text": ".faq p, .faq li"
    }
  }
}

"custom_settings": {
"token_separators": [
"-"
],
"symbols_to_index": [
"@"
]
},
"strip_chars": " .,;:#",
"stop_urls": [],
"scrape_start_urls": false,
"nb_hits": 64205
}
28 changes: 28 additions & 0 deletions typesense/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
services:
typesense:
image: typesense/typesense:0.24.0
environment:
- TYPESENSE_API_KEY=test_api_key
- TYPESENSE_DATA_DIR=/data
- TYPESENSE_ENABLE_CORS=true
ports:
- "8108:8108"
volumes:
- typesense-data:/data

scraper:
image: typesense/docsearch-scraper
volumes:
- ./config.json:/app/config.json
network_mode: "host"
environment:
- CONFIG=/app/config.json
- TYPESENSE_DATA_DIR=/data
- TYPESENSE_ENABLE_CORS=true
- TYPESENSE_API_KEY=${TYPESENSE_API_KEY:-test_api_key}
- TYPESENSE_HOST=${TYPESENSE_HOSTNAME:-localhost}
- TYPESENSE_PORT=${TYPESENSE_PORT:-8108}
- TYPESENSE_PROTOCOL=${TYPESENSE_PROTOCOL:-http}

volumes:
typesense-data:
15 changes: 15 additions & 0 deletions typesense/scripts/create-typesense-collection.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
TYPESENSE_HOST="${TYPESENSE_HOST:-http://localhost:8108}"
TYPESENSE_API_KEY="${TYPESENSE_API_KEY:-test_api_key}"

curl "${TYPESENSE_HOST}/collections" \
-X POST \
-H "Content-Type: application/json" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-d '{
"name": "mm_product_docs",
"fields": [
{"name": "category", "type": "string" },
{"name": "weight", "type": "int32" }
],
"default_sorting_field": "weight"
}'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is how we can prepare the collection to know about how we want to organize certain filterable fields. At the moment, running this script is optional as the scraper will auto generate a collection, but running this is necessary for the field customizations we want to add

7 changes: 7 additions & 0 deletions typesense/scripts/download-typesense-collection.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
TYPESENSE_HOST="${TYPESENSE_HOST:-http://localhost:8108}"
TYPESENSE_API_KEY="${TYPESENSE_API_KEY:-test_api_key}"

curl "${TYPESENSE_HOST}/collections/mm_product_docs/documents/export" \
-X GET \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-o documents.jsonl
7 changes: 7 additions & 0 deletions typesense/scripts/reset-typesense-collection.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
TYPESENSE_HOST="${TYPESENSE_HOST:-http://localhost:8108}"
TYPESENSE_API_KEY="${TYPESENSE_API_KEY:-test_api_key}"
TYPESENSE_COLLECTION_NAME="mm_product_docs"

curl -X DELETE \
"${TYPESENSE_HOST}/collections/${TYPESENSE_COLLECTION_NAME}/documents?truncate=true&filter_by=anchor:!=none" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}"