|
| 1 | +import { Callout, Steps } from 'nextra/components' |
| 2 | + |
| 3 | +# Search Bar: Site Search |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +## Introduction |
| 8 | + |
| 9 | +This guide shows how to make **new public pages** searchable via the site's **Search Bar** by updating `data.js` and **running a keyword indexer script**. ACAP configures this feature via a script in`/server/src/scripts/page_indexer/`. |
| 10 | + |
| 11 | +<Callout> |
| 12 | +**`npm run build:page_index`** indexes keywords from live public pages defined in `data.js` and saves them to the database. It runs automatically after deployment, but you can also run it locally for testing. |
| 13 | +</Callout> |
| 14 | + |
| 15 | +<Callout type="info"> |
| 16 | +**Optional:** Only needed when adding **new public pages** or updating existing ones for search indexing. |
| 17 | + |
| 18 | +> **INFO:** The search method and keyword extraction process are expected to extract keywords only from simple static pages. Pages with longer or complex content may require a different approach. |
| 19 | +</Callout> |
| 20 | +
|
| 21 | +## Add a Page to Search |
| 22 | + |
| 23 | +(Quick summary) |
| 24 | + |
| 25 | +1. Add `id` attributes to text containers in your page. |
| 26 | +2. Update `data.js` with path, name, info, and selectors. |
| 27 | +3. Run `npm run build:page_index` locally to test. |
| 28 | +4. Commit and push changes. |
| 29 | +5. Deploy and verify search results. |
| 30 | + |
| 31 | +## Detailed Steps |
| 32 | + |
| 33 | +<Steps> |
| 34 | + |
| 35 | +### Prepare the new public page for indexing |
| 36 | + |
| 37 | +- Add unique HTML `id` attributes to the container `<div>` of target elements with text content that you'd like to extract keywords from. |
| 38 | +- For example, if there is a new **About Us** page: |
| 39 | + |
| 40 | +```jsx copy |
| 41 | +return ( |
| 42 | + <Box id="about-us-content"> |
| 43 | + Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor... |
| 44 | + </Box> |
| 45 | +) |
| 46 | +``` |
| 47 | + |
| 48 | +### Inspect the public pages file definition |
| 49 | + |
| 50 | +- Open the `"/server/src/scripts/page_indexer/data.js"` file. |
| 51 | +- Observe the Object structure of the elements in the `sites[]` array, eg., the entry for the public "Weather Services" page, |
| 52 | + |
| 53 | + ```js copy |
| 54 | + const sites = [ |
| 55 | + { |
| 56 | + path: 'weather-services', |
| 57 | + name: 'ACAP Services', |
| 58 | + info: 'Seasonal and 10-Day Weather Forecasts, and Special Weather Advisory', |
| 59 | + selectors: [ |
| 60 | + '#contents-seasonal-forecast', |
| 61 | + '#contents-tenday-forecast', |
| 62 | + '#contents-special-weather-forecast' |
| 63 | + ] |
| 64 | + }, |
| 65 | + ... |
| 66 | + ] |
| 67 | + ``` |
| 68 | + |
| 69 | + <details> |
| 70 | + <summary>👉 Click to view the **`sites[]` Object key definitions**</summary> |
| 71 | + |
| 72 | + | Key | Definition | |
| 73 | + | --- | --- | |
| 74 | + | path | Frontend (NextJS) route to the target page | |
| 75 | + | name | Page title | |
| 76 | + | info | Short summary or description about the page | |
| 77 | + | selectors | Array of HTML `id` attributes in the page in which to extract keywords from. Each element starts with a `#` | |
| 78 | + |
| 79 | + </details> |
| 80 | + |
| 81 | + <Callout type="warning"> |
| 82 | + - Failing to add appropriate `"selectors"` will skip indexing the search keywords. |
| 83 | + - Ensure all public pages load correctly. There will be errors in indexing if a page is inaccessible or has loading errors. |
| 84 | + </Callout> |
| 85 | + |
| 86 | +### Add a new page file entry |
| 87 | + |
| 88 | +- Create a new entry in the `"/server/src/scripts/page_indexer/data.js"` file under the `sites[]` array corresponding to a newly-created public page. |
| 89 | +- For example, to add the **About Us** page from **step #1**: |
| 90 | + |
| 91 | + ```js copy |
| 92 | + const sites = [ |
| 93 | + { |
| 94 | + path: 'about-us', |
| 95 | + name: 'About Us', |
| 96 | + info: 'Information and details about our company', |
| 97 | + selectors: ['#about-us-content'] |
| 98 | + }, |
| 99 | + ... |
| 100 | + ] |
| 101 | + |
| 102 | +### Test extracting keywords |
| 103 | + |
| 104 | +- Set `LIVE_ORIGIN=http://localhost:3000` in the server `.env` |
| 105 | +- Run the local website |
| 106 | + ```sh copy |
| 107 | + npm run dev |
| 108 | + ``` |
| 109 | + |
| 110 | +- Open `http://localhost:3000` to verify the site is running. |
| 111 | + |
| 112 | +- Run the server NPM script |
| 113 | + ```sh copy |
| 114 | + npm run build:page_index |
| 115 | + ``` |
| 116 | + |
| 117 | + Fix errors that may occur during this step. |
| 118 | + |
| 119 | +- If there are no errors in the previous step, type keyword(s) from the sample **About Us** page in the **Search Bar**, eg., |
| 120 | + ```text copy |
| 121 | + lorem ipsum |
| 122 | + ``` |
| 123 | + |
| 124 | + The **About Us** page should display in the search results. |
| 125 | + |
| 126 | +  |
| 127 | + |
| 128 | +### Commit the `data.js` file |
| 129 | + |
| 130 | +If there are no errors in the previous steps and the search keyword(s) appear in **step #4**, proceed to commit and push the updated `data.js` file. |
| 131 | + |
| 132 | +### Deploy |
| 133 | + |
| 134 | +When you push changes, GitHub Actions will automatically run `npm run build:page_index` during deployment. Verify that the new keywords appear in the live Search Bar. |
| 135 | + |
| 136 | +</Steps> |
0 commit comments