Skip to content
Merged
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
16 changes: 10 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,18 @@ jobs:
run: npm install

- name: Build docs
env:
UPDATE_SEARCH_INDEX: ${{ github.ref == 'refs/heads/master' }}
ELASTICSEARCH_NODE: ${{ secrets.ELASTICSEARCH_NODE }}
ELASTICSEARCH_INDEX: ${{ secrets.ELASTICSEARCH_INDEX }}
ELASTICSEARCH_READ_AUTH: ${{ secrets.ELASTICSEARCH_READ_AUTH }}
ELASTICSEARCH_WRITE_AUTH: ${{ secrets.ELASTICSEARCH_WRITE_AUTH }}
run: |
npm run antora
# Build the Pagefind search index and fail the build if it is empty.
# pagefind exits 0 even when it indexes nothing (e.g. the output dir
# moved or no indexable pages were emitted), which would deploy a site
# with silently broken search. Require a non-trivial page count.
npm run pagefind | tee pagefind.log
grep -qE 'Indexed [1-9][0-9]+ pages' pagefind.log || {
echo '::error::Pagefind indexed fewer than 10 pages - search index looks broken'
exit 1
}
rm -f pagefind.log
echo 'doc.owncloud.com' > public/CNAME

- name: Save cache
Expand Down
78 changes: 10 additions & 68 deletions docs/build-the-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -392,88 +392,30 @@ Though components get sourced locally when running `npm run antora-dev-xxx`, som

The search bar is the component on the top right of the documentation where one can enter a term and get matches. If something is found, the matches are displayed as suggestions that can be clicked.

For "normal" changes, search is not necessary and may only complicate building commands and delay building times. To use the search functionality during production or development, see [Prepared npm Commands](#prepared-npm-commands) for details, some prerequisites apply. This is not only true for changes in the documentation, but also for UI changes.
Search is powered by [Pagefind](https://pagefind.app), a static search library. There is no server, container, or secret to set up: Pagefind crawls the already-built HTML in `public/` and writes a static, chunked index into `public/pagefind/`. Because it runs over the build output, the index automatically covers every component and version included in that build.

Note that ownCloud currently uses Elasticsearch version 7.x. All internal scripts and builds are therefore aligned to it and *must not* be changed, though you can use any latest minor/patch release.
Follow this procedure to build and use search locally:

Follow this procedure to show and use search and populate an index:

1. Create an `es-docker-compose.yml` file with the following content. Note that no security or passwords is needed to be set up as it is only used locally:

```
services:
elasticsearch:
image: elasticsearch:7.17.15
ports:
- 9200:9200
- 9300:9300
environment:
- discovery.type=single-node
- xpack.security.enabled=false
```

2. Start the container with the `up -d` command, use `down` to stop it.

```
docker compose -f es-docker-compose.yml up -d
```

3. To avoid a CORS Policy error, the browser must be prepared to allow access to the local Elasticsearch container. If this is not prepared, no search is possible and the browser console will return the following error:
1. Build the site as usual with any `npm run antora-xxx` command, for example:
```
Access to XMLHttpRequest at 'http://localhost:9200/' from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
```
There are several ways to fix this, only one is shown when using Chrome browsers. Install the plugin named [Allow CORS: Access-Control-Allow-Origin](https://chrome.google.com/webstore/detail/lhobafahddgcelffkeicbaginigeejlf).

4. When building docs, the following environment variables must be added to the build process. Note that you can use any `npm run antora-xxx` command:
```
UPDATE_SEARCH_INDEX=true \
ELASTICSEARCH_NODE=http://localhost:9200 \
ELASTICSEARCH_INDEX=docs \
ELASTICSEARCH_WRITE_AUTH=x:y \
npm run antora-local
```
Note that `ELASTICSEARCH_WRITE_AUTH` is necessary for building though it does not do any authentication. A value for that envvar must not be omitted but can be any dummy value you like in the format of at minimum two characters separated by a colon.

Running the build now also returns on the console:
2. Index the built site. This reads `public/` and writes `public/pagefind/`:
```
elastic: generate search index
elastic: rebuild search index
elastic: remove old search index
elastic: create empty search index
elastic: upload search index
npm run pagefind
```

5. Optionally, the status of Elasticsearch can be monitored:
`http://localhost:9200/_cat/indices?v=`
```
green open .geoip_databases Ygj4WI-STGmJrSeCfep7Tg 1 0 41 0 38.3mb 38.3mb
yellow open docs oag2dCMnS4CiSXX0Ul8plA 1 1 163 0 1.4mb 1.4mb
```
To make a dummy query after the index has been created, type the following as URL in the browser and replace `term` with what you want to search for:
`http://localhost:9200/_search?q=term`
```
{"took":45,"timed_out":false,"_shards":{"total":1,"successful":1,"skipped":0,"failed":0}, ...
```

6. To view the build result either with `npm run serve` (Antora build) or `npm run preview` (UI build) run:
The command prints a short summary of how many pages and words were indexed.

3. Serve the build and open it in the browser:
```
ELASTICSEARCH_NODE=http://localhost:9200 \
ELASTICSEARCH_INDEX=docs \
ELASTICSEARCH_READ_AUTH=x:y \
npm run serve
```

Note that for `ELASTICSEARCH_READ_AUTH`, the same applies as for `ELASTICSEARCH_WRITE_AUTH`.
4. Enter any search term into the search field to see matches returned.

7. Open the build via the browser and enter any search term as required into the search field to see matches returned.

8. Note that building against ownCloud's hosted Elasticsearch is not possible locally though you can use it for previewing the build. To do so, type the following:
```
ELASTICSEARCH_NODE=https://search.owncloud.com \
ELASTICSEARCH_INDEX=docs \
ELASTICSEARCH_READ_AUTH=docs:cADL6DDAKEBrkFMrvfxXEtYm \
npm run serve
```
In CI, the production build runs `npm run antora` followed by `npm run pagefind` before deploying `public/`, so the deployed site always ships a fresh index. Re-run `npm run pagefind` whenever the HTML changes; serving a build without indexing it first yields an empty search.

## Resolving Edit-this-page in Development

Expand Down
1 change: 0 additions & 1 deletion docs/extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ The documentation uses extensions that are added via the `site.yml` file. Some e

**Antora**

* Create an Elastic Search Index: `./ext-antora/generate-index.js`
* Load Global Site Attributes: `./ext-antora/load-global-site-attributes.js`

## Optional Extensions
Expand Down
9 changes: 0 additions & 9 deletions es-docker-compose.yml

This file was deleted.

192 changes: 0 additions & 192 deletions ext-antora/generate-index.js

This file was deleted.

Loading