Skip to content

Commit

Permalink
Merge pull request #144 from Nosto/docs-cleanup
Browse files Browse the repository at this point in the history
Modularize docs
  • Loading branch information
timowestnosto authored Jan 7, 2025
2 parents ed54356 + 1b74f9c commit fd7deba
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 4 deletions.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,14 @@
"build:liquid": "cp src/defaults/autocomplete.liquid dist/liquid/autocomplete.liquid",
"build:mustache": "cp src/defaults/autocomplete.mustache dist/mustache/autocomplete.mustache",
"build:styles": "cp src/styles.css dist/styles.css",
"build:docs": "typedoc src/index.ts",
"build:docs": "typedoc src/entries/base.ts src/entries/liquid.ts src/entries/mustache.ts src/entries/react.ts",
"build:site": "npm run build:docs && npm run test:cov && rm -rf site && cp -r ./docs ./site && cp -r ./coverage ./site/coverage",
"lint": "eslint 'src/**/*.{ts,tsx}' --cache",
"typecheck": "tsc --noEmit",
"exportTemplates": "node scripts/exportTemplates.js",
"prettify": "prettier --write \"{src,spec}/**/*.{ts,tsx}\"",
"test": "jest spec",
"test:cov": "jest --coverage spec && make-coverage-badge",
"dev:docs": "typedoc --watch src/index.ts"
"test:cov": "jest --coverage spec && make-coverage-badge"
},
"prettier": {
"trailingComma": "es5",
Expand Down
3 changes: 2 additions & 1 deletion scripts/exportTemplates.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ function generateTemplate(filePath, exportName) {
return templateLinesWithConst;
}

const hidden = "/** @hidden */"
const liquidTemplate = generateTemplate("./src/defaults/autocomplete.liquid", "defaultLiquidTemplate");
const mustacheTemplate = generateTemplate("./src/defaults/autocomplete.mustache", "defaultMustacheTemplate");

fs.writeFileSync(
"./src/defaults/_generated.ts",
liquidTemplate + `\n` + mustacheTemplate
[hidden, liquidTemplate, hidden, mustacheTemplate].join("\n")
);
11 changes: 11 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ export interface AutocompleteConfig<State> {
googleAnalytics?: GoogleAnalyticsConfig | boolean
/**
* Decorate each search hit before rendering
*
* @example
* ```ts
* import { priceDecorator } from "@nosto/autocomplete"
*
* autocomplete({
* hitDecorators: [
* priceDecorator({ defaultCurrency: "USD" })
* ]
* })
* ```
*/
hitDecorators?: HitDecorator[]
}
Expand Down
1 change: 1 addition & 0 deletions src/defaults/Autocomplete.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** @module react */
import type { SearchKeyword, SearchProduct } from "@nosto/nosto-js/client"

export interface AutocompleteProps {
Expand Down
2 changes: 2 additions & 0 deletions src/defaults/_generated.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** @hidden */
export const defaultLiquidTemplate = `
{% assign hasKeywords = response.keywords.hits.length > 0 %}
{% assign hasProducts = response.products.hits.length > 0 %}
Expand Down Expand Up @@ -98,6 +99,7 @@ export const defaultLiquidTemplate = `
</div>
`

/** @hidden */
export const defaultMustacheTemplate = `
<div class="ns-autocomplete-results">
{{#response.keywords.hits.length}}
Expand Down
1 change: 1 addition & 0 deletions src/entries/base.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** @module ./ */
export { autocomplete, type AutocompleteInstance } from "../autocomplete"
export { search } from "../search"
export { type AutocompleteConfig, type GoogleAnalyticsConfig } from "../config"
Expand Down
1 change: 1 addition & 0 deletions src/entries/liquid.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** @module liquid */
export {
fromLiquidTemplate,
fromRemoteLiquidTemplate,
Expand Down
1 change: 1 addition & 0 deletions src/entries/mustache.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/** @module mustache */
export {
fromMustacheTemplate,
fromRemoteMustacheTemplate,
Expand Down
1 change: 1 addition & 0 deletions src/entries/react.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/** @module react */
export { Autocomplete, type AutocompleteProps } from "../defaults/Autocomplete"
export * from "./base"
1 change: 1 addition & 0 deletions src/search-js/decorator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type FormattedPrices = {

/**
* Exposes currency formatting logic as a SearchProduct decorator
* Sets priceText and listPriceText fields on product and SKU level
*/
export function priceDecorator(config?: Partial<CurrencyConfig>) {
const { formatCurrency } = getCurrencyFormatting(config)
Expand Down

0 comments on commit fd7deba

Please sign in to comment.