Skip to content

Commit 4b5de80

Browse files
authored
Merge pull request #241 from gethinode/develop
Develop
2 parents 749bfeb + 73f74aa commit 4b5de80

File tree

2 files changed

+97
-2
lines changed

2 files changed

+97
-2
lines changed

CLAUDE.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
This is a Hugo module for the Hinode theme that adds full-text search functionality powered by FlexSearch. The module integrates FlexSearch as a Hugo module dependency and provides both embedded and modal search interfaces.
8+
9+
## Development Commands
10+
11+
### Building and Testing
12+
```bash
13+
npm run start # Start Hugo dev server on exampleSite (includes mod:vendor)
14+
npm run build # Build the exampleSite with Hugo (includes mod:vendor and cleanup)
15+
npm test # Run tests (executes build)
16+
npm run clean # Remove exampleSite/public and exampleSite/resources
17+
```
18+
19+
### Hugo Module Management
20+
```bash
21+
npm run mod:tidy # Tidy Hugo modules (runs on both root and exampleSite)
22+
npm run mod:update # Update all Hugo modules to latest versions
23+
npm run mod:vendor # Vendor Hugo modules into _vendor directory
24+
```
25+
26+
### Commits
27+
This project uses Conventional Commits enforced by commitlint and husky. Use `npx git-cz` to create properly formatted commit messages. Semantic-release automatically handles versioning and releases from the main branch.
28+
29+
## Architecture
30+
31+
### Module Structure
32+
33+
The repository follows Hugo's module structure with module mounts defined in `config.toml`:
34+
- **assets/**: JavaScript (FlexSearch implementation), SCSS (search styling), SVG icons
35+
- **layouts/**: Hugo templates (partials, shortcodes)
36+
- **i18n/**: Translation files for search UI text
37+
- **content/**: Content mounts (including modal template)
38+
- **exampleSite/**: Test site that imports this module
39+
40+
The module imports `github.com/nextapps-de/flexsearch` and mounts its bundle to `assets/js/modules/flexsearch/flexsearch.bundle.min.js`.
41+
42+
### Search Implementation
43+
44+
**Two search modes** are supported via `params.navigation.search.modal` configuration:
45+
1. **Embedded mode** (default): Search input in navigation bar with dropdown suggestions
46+
2. **Modal mode**: Full-screen modal dialog triggered by a button/icon
47+
48+
**Key components:**
49+
50+
- `layouts/_partials/utilities/GetSearchConfig.html`: Returns search configuration (enabled, modal, icon) with backwards compatibility for deprecated parameter names
51+
- `layouts/_partials/assets/search-input.html`: Embedded search form HTML structure
52+
- `layouts/_shortcodes/ModalSearch.html`: Modal search dialog structure
53+
- `layouts/_partials/assets/search-meta.html`: Recursive helper to extract frontmatter content for indexing
54+
- `assets/js/modules/flexsearch/flexsearch.index.js`: FlexSearch initialization and search logic
55+
56+
**Search index configuration:**
57+
- The JavaScript file generates a FlexSearch document index at build time from Hugo's page content
58+
- Indexes three fields: `title` (forward tokenization), `description`, and `content` (full tokenization)
59+
- Supports optional frontmatter indexing via `flexsearch.frontmatter` parameter
60+
- Can use absolute URLs via `flexsearch.canonifyURLs` parameter
61+
- Pages can be excluded with `searchExclude: true` in frontmatter
62+
- Supports optional `indexTitle` parameter to override title in search results
63+
64+
**Search behavior:**
65+
- Shows up to 5 results across title, description, and content fields
66+
- Deduplicates results by URL
67+
- Keyboard shortcuts: Ctrl+/ to focus, Escape to close, Arrow keys for navigation
68+
- Results appear in a dropdown with title and description snippets
69+
70+
### Internationalization
71+
72+
Translation files in `i18n/` provide localized strings for:
73+
- `ui_search`: Search input placeholder and aria-label
74+
- `ui_no_results`: Message when no results found
75+
76+
Supported languages: en, de, fr, nl, pl, zh-hans, zh-hant
77+
78+
### Configuration Parameters
79+
80+
Module configuration in `config.toml` under `params.modules.flexsearch`:
81+
- `canonifyURLs` (default: false): Use absolute URLs instead of relative
82+
- `frontmatter` (default: false): Include frontmatter content in search index
83+
- `filter` (default: "params"): Restrict frontmatter scanning to specific key
84+
- `localize` (default: true): Enable language-specific search
85+
86+
Navigation configuration under `params.navigation.search`:
87+
- `enabled` (default: false): Enable search in navigation
88+
- `modal` (default: false): Use modal instead of embedded search
89+
- `icon` (default: "fas magnifying-glass"): Icon for modal search button
90+
91+
## Testing Locally
92+
93+
The `exampleSite/` directory contains a minimal Hugo site that imports this module using a local replacement path. Changes to the module are reflected immediately when running the dev server.

layouts/_partials/utilities/GetSearchConfig.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
{{- $searchArg := .search | default false -}}
21
{{- $searchDefault := false -}}
32
{{- $searchModal := false -}}
43
{{- $searchIcon := "fas magnifying-glass" }}
@@ -11,7 +10,10 @@
1110
{{- $searchModal = site.Params.navigation.search.modal -}}
1211
{{- $searchIcon = site.Params.navigation.search.icon | default $searchIcon }}
1312
{{ end }}
14-
{{- $search := $searchArg | default $searchDefault -}}
13+
{{- $search := $searchDefault -}}
14+
{{- if isset . "search" -}}
15+
{{- $search = .search -}}
16+
{{- end -}}
1517
{{- $searchModal = and $search $searchModal -}}
1618
{{ if isset site.Params.navigation "searchmodal" }}
1719
{{ warnf "site parameter %q: deprecated in v%s, use %q instead" "navigation.searchModal" "1.12.0" "navigation.search.modal" }}

0 commit comments

Comments
 (0)