@docusaurus/theme-search-algolia 0.0.0-5014 → 0.0.0-5026

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,4 +4,4 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- export {useAlgoliaContextualFacetFilters} from './useAlgoliaContextualFacetFilters';
7
+ export { useAlgoliaContextualFacetFilters } from './useAlgoliaContextualFacetFilters';
@@ -4,12 +4,12 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import {useContextualSearchFilters} from '@docusaurus/theme-common';
7
+ import { useContextualSearchFilters } from '@docusaurus/theme-common';
8
8
  // Translate search-engine agnostic search filters to Algolia search filters
9
9
  export function useAlgoliaContextualFacetFilters() {
10
- const {locale, tags} = useContextualSearchFilters();
11
- // Seems safe to convert locale->language, see AlgoliaSearchMetadata comment
12
- const languageFilter = `language:${locale}`;
13
- const tagsFilter = tags.map((tag) => `docusaurus_tag:${tag}`);
14
- return [languageFilter, tagsFilter];
10
+ const { locale, tags } = useContextualSearchFilters();
11
+ // Seems safe to convert locale->language, see AlgoliaSearchMetadata comment
12
+ const languageFilter = `language:${locale}`;
13
+ const tagsFilter = tags.map((tag) => `docusaurus_tag:${tag}`);
14
+ return [languageFilter, tagsFilter];
15
15
  }
package/lib/index.js CHANGED
@@ -1,107 +1,90 @@
1
- 'use strict';
1
+ "use strict";
2
2
  /**
3
3
  * Copyright (c) Facebook, Inc. and its affiliates.
4
4
  *
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
- Object.defineProperty(exports, '__esModule', {value: true});
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.validateThemeConfig = void 0;
10
- const tslib_1 = require('tslib');
11
- const path_1 = tslib_1.__importDefault(require('path'));
12
- const fs_extra_1 = tslib_1.__importDefault(require('fs-extra'));
13
- const lodash_1 = tslib_1.__importDefault(require('lodash'));
14
- const logger_1 = tslib_1.__importDefault(require('@docusaurus/logger'));
15
- const eta_1 = require('eta');
16
- const utils_1 = require('@docusaurus/utils');
17
- const theme_translations_1 = require('@docusaurus/theme-translations');
18
- const opensearch_1 = tslib_1.__importDefault(require('./templates/opensearch'));
19
- const getCompiledOpenSearchTemplate = lodash_1.default.memoize(() =>
20
- (0, eta_1.compile)(opensearch_1.default.trim()),
21
- );
10
+ const tslib_1 = require("tslib");
11
+ const path_1 = tslib_1.__importDefault(require("path"));
12
+ const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
13
+ const lodash_1 = tslib_1.__importDefault(require("lodash"));
14
+ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
15
+ const eta_1 = require("eta");
16
+ const utils_1 = require("@docusaurus/utils");
17
+ const theme_translations_1 = require("@docusaurus/theme-translations");
18
+ const opensearch_1 = tslib_1.__importDefault(require("./templates/opensearch"));
19
+ const getCompiledOpenSearchTemplate = lodash_1.default.memoize(() => (0, eta_1.compile)(opensearch_1.default.trim()));
22
20
  function renderOpenSearchTemplate(data) {
23
- const compiled = getCompiledOpenSearchTemplate();
24
- return compiled(data, eta_1.defaultConfig);
21
+ const compiled = getCompiledOpenSearchTemplate();
22
+ return compiled(data, eta_1.defaultConfig);
25
23
  }
26
24
  const OPEN_SEARCH_FILENAME = 'opensearch.xml';
27
25
  function themeSearchAlgolia(context) {
28
- const {
29
- baseUrl,
30
- siteConfig: {title, url, favicon, themeConfig},
31
- i18n: {currentLocale},
32
- } = context;
33
- const {
34
- algolia: {searchPagePath},
35
- } = themeConfig;
36
- return {
37
- name: 'docusaurus-theme-search-algolia',
38
- getThemePath() {
39
- return '../lib/theme';
40
- },
41
- getTypeScriptThemePath() {
42
- return '../src/theme';
43
- },
44
- getDefaultCodeTranslationMessages() {
45
- return (0, theme_translations_1.readDefaultCodeTranslationMessages)({
46
- locale: currentLocale,
47
- name: 'theme-search-algolia',
48
- });
49
- },
50
- async contentLoaded({actions: {addRoute}}) {
51
- if (searchPagePath) {
52
- addRoute({
53
- path: (0, utils_1.normalizeUrl)([baseUrl, searchPagePath]),
54
- component: '@theme/SearchPage',
55
- exact: true,
56
- });
57
- }
58
- },
59
- async postBuild({outDir}) {
60
- if (searchPagePath) {
61
- const siteUrl = (0, utils_1.normalizeUrl)([url, baseUrl]);
62
- try {
63
- await fs_extra_1.default.writeFile(
64
- path_1.default.join(outDir, OPEN_SEARCH_FILENAME),
65
- renderOpenSearchTemplate({
66
- title,
67
- siteUrl,
68
- searchUrl: (0, utils_1.normalizeUrl)([siteUrl, searchPagePath]),
69
- faviconUrl: favicon
70
- ? (0, utils_1.normalizeUrl)([siteUrl, favicon])
71
- : null,
72
- }),
73
- );
74
- } catch (err) {
75
- logger_1.default.error('Generating OpenSearch file failed.');
76
- throw err;
77
- }
78
- }
79
- },
80
- injectHtmlTags() {
81
- if (!searchPagePath) {
82
- return {};
83
- }
84
- return {
85
- headTags: [
86
- {
87
- tagName: 'link',
88
- attributes: {
89
- rel: 'search',
90
- type: 'application/opensearchdescription+xml',
91
- title,
92
- href: (0, utils_1.normalizeUrl)([baseUrl, OPEN_SEARCH_FILENAME]),
93
- },
94
- },
95
- ],
96
- };
97
- },
98
- };
26
+ const { baseUrl, siteConfig: { title, url, favicon, themeConfig }, i18n: { currentLocale }, } = context;
27
+ const { algolia: { searchPagePath }, } = themeConfig;
28
+ return {
29
+ name: 'docusaurus-theme-search-algolia',
30
+ getThemePath() {
31
+ return '../lib/theme';
32
+ },
33
+ getTypeScriptThemePath() {
34
+ return '../src/theme';
35
+ },
36
+ getDefaultCodeTranslationMessages() {
37
+ return (0, theme_translations_1.readDefaultCodeTranslationMessages)({
38
+ locale: currentLocale,
39
+ name: 'theme-search-algolia',
40
+ });
41
+ },
42
+ async contentLoaded({ actions: { addRoute } }) {
43
+ if (searchPagePath) {
44
+ addRoute({
45
+ path: (0, utils_1.normalizeUrl)([baseUrl, searchPagePath]),
46
+ component: '@theme/SearchPage',
47
+ exact: true,
48
+ });
49
+ }
50
+ },
51
+ async postBuild({ outDir }) {
52
+ if (searchPagePath) {
53
+ const siteUrl = (0, utils_1.normalizeUrl)([url, baseUrl]);
54
+ try {
55
+ await fs_extra_1.default.writeFile(path_1.default.join(outDir, OPEN_SEARCH_FILENAME), renderOpenSearchTemplate({
56
+ title,
57
+ siteUrl,
58
+ searchUrl: (0, utils_1.normalizeUrl)([siteUrl, searchPagePath]),
59
+ faviconUrl: favicon ? (0, utils_1.normalizeUrl)([siteUrl, favicon]) : null,
60
+ }));
61
+ }
62
+ catch (err) {
63
+ logger_1.default.error('Generating OpenSearch file failed.');
64
+ throw err;
65
+ }
66
+ }
67
+ },
68
+ injectHtmlTags() {
69
+ if (!searchPagePath) {
70
+ return {};
71
+ }
72
+ return {
73
+ headTags: [
74
+ {
75
+ tagName: 'link',
76
+ attributes: {
77
+ rel: 'search',
78
+ type: 'application/opensearchdescription+xml',
79
+ title,
80
+ href: (0, utils_1.normalizeUrl)([baseUrl, OPEN_SEARCH_FILENAME]),
81
+ },
82
+ },
83
+ ],
84
+ };
85
+ },
86
+ };
99
87
  }
100
88
  exports.default = themeSearchAlgolia;
101
- var validateThemeConfig_1 = require('./validateThemeConfig');
102
- Object.defineProperty(exports, 'validateThemeConfig', {
103
- enumerable: true,
104
- get: function () {
105
- return validateThemeConfig_1.validateThemeConfig;
106
- },
107
- });
89
+ var validateThemeConfig_1 = require("./validateThemeConfig");
90
+ Object.defineProperty(exports, "validateThemeConfig", { enumerable: true, get: function () { return validateThemeConfig_1.validateThemeConfig; } });
@@ -1,11 +1,11 @@
1
- 'use strict';
1
+ "use strict";
2
2
  /**
3
3
  * Copyright (c) Facebook, Inc. and its affiliates.
4
4
  *
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
- Object.defineProperty(exports, '__esModule', {value: true});
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.default = `
10
10
  <?xml version="1.0" encoding="UTF-8"?>
11
11
  <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"
@@ -1,50 +1,44 @@
1
- 'use strict';
1
+ "use strict";
2
2
  /**
3
3
  * Copyright (c) Facebook, Inc. and its affiliates.
4
4
  *
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
- Object.defineProperty(exports, '__esModule', {value: true});
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.validateThemeConfig = exports.Schema = exports.DEFAULT_CONFIG = void 0;
10
- const utils_validation_1 = require('@docusaurus/utils-validation');
10
+ const utils_validation_1 = require("@docusaurus/utils-validation");
11
11
  exports.DEFAULT_CONFIG = {
12
- // Enabled by default, as it makes sense in most cases
13
- // see also https://github.com/facebook/docusaurus/issues/5880
14
- contextualSearch: true,
15
- searchParameters: {},
16
- searchPagePath: 'search',
12
+ // Enabled by default, as it makes sense in most cases
13
+ // see also https://github.com/facebook/docusaurus/issues/5880
14
+ contextualSearch: true,
15
+ searchParameters: {},
16
+ searchPagePath: 'search',
17
17
  };
18
18
  exports.Schema = utils_validation_1.Joi.object({
19
- algolia: utils_validation_1.Joi.object({
20
- // Docusaurus attributes
21
- contextualSearch: utils_validation_1.Joi.boolean().default(
22
- exports.DEFAULT_CONFIG.contextualSearch,
23
- ),
24
- externalUrlRegex: utils_validation_1.Joi.string().optional(),
25
- // Algolia attributes
26
- appId: utils_validation_1.Joi.string().required().messages({
27
- 'any.required':
28
- '"algolia.appId" is required. If you haven\'t migrated to the new DocSearch infra, please refer to the blog post for instructions: https://docusaurus.io/blog/2021/11/21/algolia-docsearch-migration',
29
- }),
30
- apiKey: utils_validation_1.Joi.string().required(),
31
- indexName: utils_validation_1.Joi.string().required(),
32
- searchParameters: utils_validation_1.Joi.object()
33
- .default(exports.DEFAULT_CONFIG.searchParameters)
34
- .unknown(),
35
- searchPagePath: utils_validation_1.Joi.alternatives()
36
- .try(
37
- utils_validation_1.Joi.boolean().invalid(true),
38
- utils_validation_1.Joi.string(),
39
- )
40
- .allow(null)
41
- .default(exports.DEFAULT_CONFIG.searchPagePath),
42
- })
43
- .label('themeConfig.algolia')
44
- .required()
45
- .unknown(), // DocSearch 3 is still alpha: don't validate the rest for now
19
+ algolia: utils_validation_1.Joi.object({
20
+ // Docusaurus attributes
21
+ contextualSearch: utils_validation_1.Joi.boolean().default(exports.DEFAULT_CONFIG.contextualSearch),
22
+ externalUrlRegex: utils_validation_1.Joi.string().optional(),
23
+ // Algolia attributes
24
+ appId: utils_validation_1.Joi.string().required().messages({
25
+ 'any.required': '"algolia.appId" is required. If you haven\'t migrated to the new DocSearch infra, please refer to the blog post for instructions: https://docusaurus.io/blog/2021/11/21/algolia-docsearch-migration',
26
+ }),
27
+ apiKey: utils_validation_1.Joi.string().required(),
28
+ indexName: utils_validation_1.Joi.string().required(),
29
+ searchParameters: utils_validation_1.Joi.object()
30
+ .default(exports.DEFAULT_CONFIG.searchParameters)
31
+ .unknown(),
32
+ searchPagePath: utils_validation_1.Joi.alternatives()
33
+ .try(utils_validation_1.Joi.boolean().invalid(true), utils_validation_1.Joi.string())
34
+ .allow(null)
35
+ .default(exports.DEFAULT_CONFIG.searchPagePath),
36
+ })
37
+ .label('themeConfig.algolia')
38
+ .required()
39
+ .unknown(), // DocSearch 3 is still alpha: don't validate the rest for now
46
40
  });
47
- function validateThemeConfig({validate, themeConfig}) {
48
- return validate(exports.Schema, themeConfig);
41
+ function validateThemeConfig({ validate, themeConfig, }) {
42
+ return validate(exports.Schema, themeConfig);
49
43
  }
50
44
  exports.validateThemeConfig = validateThemeConfig;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/theme-search-algolia",
3
- "version": "0.0.0-5014",
3
+ "version": "0.0.0-5026",
4
4
  "description": "Algolia search component for Docusaurus.",
5
5
  "main": "lib/index.js",
6
6
  "sideEffects": [
@@ -21,21 +21,17 @@
21
21
  },
22
22
  "license": "MIT",
23
23
  "scripts": {
24
- "build": "yarn build:server && yarn build:client && yarn build:copy && yarn build:format",
25
- "build:server": "tsc --project tsconfig.server.json",
26
- "build:client": "tsc --project tsconfig.client.json",
27
- "build:copy": "node copyUntypedFiles.mjs",
28
- "build:format": "prettier --config ../../.prettierrc --write \"lib/**/*.js\""
24
+ "build": "tsc --build && node copyUntypedFiles.mjs && prettier --config ../../.prettierrc --write \"lib/theme/**/*.js\""
29
25
  },
30
26
  "dependencies": {
31
27
  "@docsearch/react": "^3.0.0",
32
- "@docusaurus/core": "0.0.0-5014",
33
- "@docusaurus/logger": "0.0.0-5014",
34
- "@docusaurus/plugin-content-docs": "0.0.0-5014",
35
- "@docusaurus/theme-common": "0.0.0-5014",
36
- "@docusaurus/theme-translations": "0.0.0-5014",
37
- "@docusaurus/utils": "0.0.0-5014",
38
- "@docusaurus/utils-validation": "0.0.0-5014",
28
+ "@docusaurus/core": "0.0.0-5026",
29
+ "@docusaurus/logger": "0.0.0-5026",
30
+ "@docusaurus/plugin-content-docs": "0.0.0-5026",
31
+ "@docusaurus/theme-common": "0.0.0-5026",
32
+ "@docusaurus/theme-translations": "0.0.0-5026",
33
+ "@docusaurus/utils": "0.0.0-5026",
34
+ "@docusaurus/utils-validation": "0.0.0-5026",
39
35
  "algoliasearch": "^4.13.0",
40
36
  "algoliasearch-helper": "^3.8.2",
41
37
  "clsx": "^1.1.1",
@@ -46,7 +42,7 @@
46
42
  "utility-types": "^3.10.0"
47
43
  },
48
44
  "devDependencies": {
49
- "@docusaurus/module-type-aliases": "0.0.0-5014"
45
+ "@docusaurus/module-type-aliases": "0.0.0-5026"
50
46
  },
51
47
  "peerDependencies": {
52
48
  "react": "^16.8.4 || ^17.0.0",
@@ -55,5 +51,5 @@
55
51
  "engines": {
56
52
  "node": ">=14"
57
53
  },
58
- "gitHead": "f1ab067eeed93212a8e8034d621924d60aba741d"
54
+ "gitHead": "92c87e08aea2de43e9ac16c5c8aa8112ea1c85ac"
59
55
  }