decap-cms-core 2.56.0-beta.1
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.
- package/LICENSE +22 -0
- package/README.md +9 -0
- package/dist/decap-cms-core.js +47 -0
- package/dist/decap-cms-core.js.LICENSE.txt +109 -0
- package/dist/decap-cms-core.js.map +1 -0
- package/dist/esm/actions/auth.js +118 -0
- package/dist/esm/actions/collections.js +23 -0
- package/dist/esm/actions/config.js +482 -0
- package/dist/esm/actions/deploys.js +89 -0
- package/dist/esm/actions/editorialWorkflow.js +511 -0
- package/dist/esm/actions/entries.js +940 -0
- package/dist/esm/actions/media.js +168 -0
- package/dist/esm/actions/mediaLibrary.js +606 -0
- package/dist/esm/actions/notifications.js +32 -0
- package/dist/esm/actions/search.js +156 -0
- package/dist/esm/actions/status.js +93 -0
- package/dist/esm/actions/waitUntil.js +39 -0
- package/dist/esm/backend.js +1073 -0
- package/dist/esm/bootstrap.js +107 -0
- package/dist/esm/components/App/App.js +301 -0
- package/dist/esm/components/App/Header.js +162 -0
- package/dist/esm/components/App/NotFoundPage.js +27 -0
- package/dist/esm/components/Collection/Collection.js +210 -0
- package/dist/esm/components/Collection/CollectionControls.js +54 -0
- package/dist/esm/components/Collection/CollectionSearch.js +235 -0
- package/dist/esm/components/Collection/CollectionTop.js +77 -0
- package/dist/esm/components/Collection/ControlButton.js +23 -0
- package/dist/esm/components/Collection/Entries/Entries.js +74 -0
- package/dist/esm/components/Collection/Entries/EntriesCollection.js +193 -0
- package/dist/esm/components/Collection/Entries/EntriesSearch.js +117 -0
- package/dist/esm/components/Collection/Entries/EntryCard.js +134 -0
- package/dist/esm/components/Collection/Entries/EntryListing.js +120 -0
- package/dist/esm/components/Collection/FilterControl.js +41 -0
- package/dist/esm/components/Collection/GroupControl.js +41 -0
- package/dist/esm/components/Collection/NestedCollection.js +311 -0
- package/dist/esm/components/Collection/Sidebar.js +102 -0
- package/dist/esm/components/Collection/SortControl.js +67 -0
- package/dist/esm/components/Collection/ViewStyleControl.js +47 -0
- package/dist/esm/components/Editor/Editor.js +479 -0
- package/dist/esm/components/Editor/EditorControlPane/EditorControl.js +393 -0
- package/dist/esm/components/Editor/EditorControlPane/EditorControlPane.js +259 -0
- package/dist/esm/components/Editor/EditorControlPane/Widget.js +355 -0
- package/dist/esm/components/Editor/EditorInterface.js +401 -0
- package/dist/esm/components/Editor/EditorPreviewPane/EditorPreview.js +56 -0
- package/dist/esm/components/Editor/EditorPreviewPane/EditorPreviewContent.js +34 -0
- package/dist/esm/components/Editor/EditorPreviewPane/EditorPreviewPane.js +252 -0
- package/dist/esm/components/Editor/EditorPreviewPane/PreviewHOC.js +39 -0
- package/dist/esm/components/Editor/EditorToolbar.js +551 -0
- package/dist/esm/components/Editor/withWorkflow.js +64 -0
- package/dist/esm/components/EditorWidgets/Unknown/UnknownControl.js +26 -0
- package/dist/esm/components/EditorWidgets/Unknown/UnknownPreview.js +28 -0
- package/dist/esm/components/EditorWidgets/index.js +7 -0
- package/dist/esm/components/MediaLibrary/EmptyMessage.js +30 -0
- package/dist/esm/components/MediaLibrary/MediaLibrary.js +444 -0
- package/dist/esm/components/MediaLibrary/MediaLibraryButtons.js +110 -0
- package/dist/esm/components/MediaLibrary/MediaLibraryCard.js +108 -0
- package/dist/esm/components/MediaLibrary/MediaLibraryCardGrid.js +211 -0
- package/dist/esm/components/MediaLibrary/MediaLibraryHeader.js +40 -0
- package/dist/esm/components/MediaLibrary/MediaLibraryModal.js +163 -0
- package/dist/esm/components/MediaLibrary/MediaLibrarySearch.js +60 -0
- package/dist/esm/components/MediaLibrary/MediaLibraryTop.js +134 -0
- package/dist/esm/components/UI/DragDrop.js +84 -0
- package/dist/esm/components/UI/ErrorBoundary.js +184 -0
- package/dist/esm/components/UI/FileUploadButton.js +34 -0
- package/dist/esm/components/UI/Modal.js +113 -0
- package/dist/esm/components/UI/Notifications.js +74 -0
- package/dist/esm/components/UI/SettingsDropdown.js +118 -0
- package/dist/esm/components/UI/index.js +60 -0
- package/dist/esm/components/Workflow/Workflow.js +144 -0
- package/dist/esm/components/Workflow/WorkflowCard.js +137 -0
- package/dist/esm/components/Workflow/WorkflowList.js +219 -0
- package/dist/esm/constants/collectionTypes.js +10 -0
- package/dist/esm/constants/collectionViews.js +10 -0
- package/dist/esm/constants/commitProps.js +10 -0
- package/dist/esm/constants/configSchema.js +594 -0
- package/dist/esm/constants/fieldInference.js +67 -0
- package/dist/esm/constants/publishModes.js +28 -0
- package/dist/esm/constants/validationErrorTypes.js +13 -0
- package/dist/esm/formats/formats.js +82 -0
- package/dist/esm/formats/frontmatter.js +163 -0
- package/dist/esm/formats/helpers.js +18 -0
- package/dist/esm/formats/json.js +15 -0
- package/dist/esm/formats/toml.js +40 -0
- package/dist/esm/formats/yaml.js +63 -0
- package/dist/esm/index.js +20 -0
- package/dist/esm/integrations/index.js +37 -0
- package/dist/esm/integrations/providers/algolia/implementation.js +184 -0
- package/dist/esm/integrations/providers/assetStore/implementation.js +175 -0
- package/dist/esm/lib/consoleError.js +9 -0
- package/dist/esm/lib/formatters.js +204 -0
- package/dist/esm/lib/i18n.js +381 -0
- package/dist/esm/lib/phrases.js +13 -0
- package/dist/esm/lib/registry.js +322 -0
- package/dist/esm/lib/serializeEntryValues.js +74 -0
- package/dist/esm/lib/textHelper.js +15 -0
- package/dist/esm/lib/urlHelper.js +128 -0
- package/dist/esm/mediaLibrary.js +42 -0
- package/dist/esm/reducers/auth.js +35 -0
- package/dist/esm/reducers/collections.js +424 -0
- package/dist/esm/reducers/combinedReducer.js +19 -0
- package/dist/esm/reducers/config.js +42 -0
- package/dist/esm/reducers/cursors.js +38 -0
- package/dist/esm/reducers/deploys.js +53 -0
- package/dist/esm/reducers/editorialWorkflow.js +98 -0
- package/dist/esm/reducers/entries.js +591 -0
- package/dist/esm/reducers/entryDraft.js +184 -0
- package/dist/esm/reducers/globalUI.js +32 -0
- package/dist/esm/reducers/index.js +84 -0
- package/dist/esm/reducers/integrations.js +68 -0
- package/dist/esm/reducers/mediaLibrary.js +265 -0
- package/dist/esm/reducers/medias.js +76 -0
- package/dist/esm/reducers/notifications.js +36 -0
- package/dist/esm/reducers/search.js +89 -0
- package/dist/esm/reducers/status.js +37 -0
- package/dist/esm/redux/index.js +14 -0
- package/dist/esm/redux/middleware/waitUntilAction.js +56 -0
- package/dist/esm/routing/history.js +21 -0
- package/dist/esm/types/diacritics.d.js +1 -0
- package/dist/esm/types/global.d.js +5 -0
- package/dist/esm/types/immutable.js +5 -0
- package/dist/esm/types/redux.js +16 -0
- package/dist/esm/types/tomlify-j0.4.d.js +1 -0
- package/dist/esm/valueObjects/AssetProxy.js +60 -0
- package/dist/esm/valueObjects/EditorComponent.js +48 -0
- package/dist/esm/valueObjects/Entry.js +27 -0
- package/index.d.ts +587 -0
- package/package.json +102 -0
- package/src/__tests__/backend.spec.js +934 -0
- package/src/actions/__tests__/config.spec.js +1009 -0
- package/src/actions/__tests__/editorialWorkflow.spec.js +216 -0
- package/src/actions/__tests__/entries.spec.js +575 -0
- package/src/actions/__tests__/media.spec.ts +171 -0
- package/src/actions/__tests__/mediaLibrary.spec.js +327 -0
- package/src/actions/__tests__/search.spec.js +209 -0
- package/src/actions/auth.ts +127 -0
- package/src/actions/collections.ts +18 -0
- package/src/actions/config.ts +538 -0
- package/src/actions/deploys.ts +104 -0
- package/src/actions/editorialWorkflow.ts +567 -0
- package/src/actions/entries.ts +1041 -0
- package/src/actions/media.ts +139 -0
- package/src/actions/mediaLibrary.ts +574 -0
- package/src/actions/notifications.ts +36 -0
- package/src/actions/search.ts +194 -0
- package/src/actions/status.ts +99 -0
- package/src/actions/waitUntil.ts +49 -0
- package/src/backend.ts +1342 -0
- package/src/bootstrap.js +102 -0
- package/src/components/App/App.js +280 -0
- package/src/components/App/Header.js +236 -0
- package/src/components/App/NotFoundPage.js +23 -0
- package/src/components/Collection/Collection.js +205 -0
- package/src/components/Collection/CollectionControls.js +58 -0
- package/src/components/Collection/CollectionSearch.js +238 -0
- package/src/components/Collection/CollectionTop.js +81 -0
- package/src/components/Collection/ControlButton.js +27 -0
- package/src/components/Collection/Entries/Entries.js +73 -0
- package/src/components/Collection/Entries/EntriesCollection.js +165 -0
- package/src/components/Collection/Entries/EntriesSearch.js +91 -0
- package/src/components/Collection/Entries/EntryCard.js +167 -0
- package/src/components/Collection/Entries/EntryListing.js +86 -0
- package/src/components/Collection/Entries/__tests__/EntriesCollection.spec.js +155 -0
- package/src/components/Collection/Entries/__tests__/__snapshots__/EntriesCollection.spec.js.snap +49 -0
- package/src/components/Collection/FilterControl.js +39 -0
- package/src/components/Collection/GroupControl.js +39 -0
- package/src/components/Collection/NestedCollection.js +309 -0
- package/src/components/Collection/Sidebar.js +130 -0
- package/src/components/Collection/SortControl.js +68 -0
- package/src/components/Collection/ViewStyleControl.js +50 -0
- package/src/components/Collection/__tests__/Collection.spec.js +75 -0
- package/src/components/Collection/__tests__/NestedCollection.spec.js +442 -0
- package/src/components/Collection/__tests__/Sidebar.spec.js +87 -0
- package/src/components/Collection/__tests__/__snapshots__/Collection.spec.js.snap +144 -0
- package/src/components/Collection/__tests__/__snapshots__/NestedCollection.spec.js.snap +550 -0
- package/src/components/Collection/__tests__/__snapshots__/Sidebar.spec.js.snap +308 -0
- package/src/components/Editor/Editor.js +494 -0
- package/src/components/Editor/EditorControlPane/EditorControl.js +428 -0
- package/src/components/Editor/EditorControlPane/EditorControlPane.js +256 -0
- package/src/components/Editor/EditorControlPane/Widget.js +351 -0
- package/src/components/Editor/EditorInterface.js +434 -0
- package/src/components/Editor/EditorPreviewPane/EditorPreview.js +40 -0
- package/src/components/Editor/EditorPreviewPane/EditorPreviewContent.js +34 -0
- package/src/components/Editor/EditorPreviewPane/EditorPreviewPane.js +278 -0
- package/src/components/Editor/EditorPreviewPane/PreviewHOC.js +33 -0
- package/src/components/Editor/EditorToolbar.js +678 -0
- package/src/components/Editor/__tests__/Editor.spec.js +219 -0
- package/src/components/Editor/__tests__/EditorToolbar.spec.js +120 -0
- package/src/components/Editor/__tests__/__snapshots__/Editor.spec.js.snap +45 -0
- package/src/components/Editor/__tests__/__snapshots__/EditorToolbar.spec.js.snap +4020 -0
- package/src/components/Editor/withWorkflow.js +61 -0
- package/src/components/EditorWidgets/Unknown/UnknownControl.js +17 -0
- package/src/components/EditorWidgets/Unknown/UnknownPreview.js +19 -0
- package/src/components/EditorWidgets/index.js +5 -0
- package/src/components/MediaLibrary/EmptyMessage.js +28 -0
- package/src/components/MediaLibrary/MediaLibrary.js +407 -0
- package/src/components/MediaLibrary/MediaLibraryButtons.js +136 -0
- package/src/components/MediaLibrary/MediaLibraryCard.js +128 -0
- package/src/components/MediaLibrary/MediaLibraryCardGrid.js +199 -0
- package/src/components/MediaLibrary/MediaLibraryHeader.js +48 -0
- package/src/components/MediaLibrary/MediaLibraryModal.js +200 -0
- package/src/components/MediaLibrary/MediaLibrarySearch.js +61 -0
- package/src/components/MediaLibrary/MediaLibraryTop.js +143 -0
- package/src/components/MediaLibrary/__tests__/MediaLibraryButtons.spec.js +45 -0
- package/src/components/MediaLibrary/__tests__/MediaLibraryCard.spec.js +49 -0
- package/src/components/MediaLibrary/__tests__/__snapshots__/MediaLibraryCard.spec.js.snap +216 -0
- package/src/components/UI/DragDrop.js +66 -0
- package/src/components/UI/ErrorBoundary.js +209 -0
- package/src/components/UI/FileUploadButton.js +24 -0
- package/src/components/UI/Modal.js +109 -0
- package/src/components/UI/Notifications.tsx +83 -0
- package/src/components/UI/SettingsDropdown.js +103 -0
- package/src/components/UI/__tests__/ErrorBoundary.spec.js +57 -0
- package/src/components/UI/index.js +6 -0
- package/src/components/Workflow/Workflow.js +166 -0
- package/src/components/Workflow/WorkflowCard.js +177 -0
- package/src/components/Workflow/WorkflowList.js +269 -0
- package/src/constants/__tests__/configSchema.spec.js +511 -0
- package/src/constants/collectionTypes.ts +2 -0
- package/src/constants/collectionViews.js +2 -0
- package/src/constants/commitProps.ts +2 -0
- package/src/constants/configSchema.js +399 -0
- package/src/constants/fieldInference.tsx +78 -0
- package/src/constants/publishModes.ts +22 -0
- package/src/constants/validationErrorTypes.js +6 -0
- package/src/formats/__tests__/frontmatter.spec.js +429 -0
- package/src/formats/__tests__/toml.spec.js +9 -0
- package/src/formats/__tests__/yaml.spec.js +162 -0
- package/src/formats/formats.ts +86 -0
- package/src/formats/frontmatter.ts +150 -0
- package/src/formats/helpers.ts +14 -0
- package/src/formats/json.ts +9 -0
- package/src/formats/toml.ts +33 -0
- package/src/formats/yaml.ts +58 -0
- package/src/index.js +8 -0
- package/src/integrations/index.js +35 -0
- package/src/integrations/providers/algolia/implementation.js +176 -0
- package/src/integrations/providers/assetStore/implementation.js +147 -0
- package/src/lib/__tests__/formatters.spec.js +723 -0
- package/src/lib/__tests__/i18n.spec.js +792 -0
- package/src/lib/__tests__/phrases.spec.js +119 -0
- package/src/lib/__tests__/registry.spec.js +246 -0
- package/src/lib/__tests__/serializeEntryValues.spec.js +22 -0
- package/src/lib/__tests__/urlHelper.spec.js +138 -0
- package/src/lib/consoleError.js +7 -0
- package/src/lib/formatters.ts +267 -0
- package/src/lib/i18n.ts +427 -0
- package/src/lib/phrases.js +8 -0
- package/src/lib/registry.js +282 -0
- package/src/lib/serializeEntryValues.js +75 -0
- package/src/lib/textHelper.js +11 -0
- package/src/lib/urlHelper.ts +125 -0
- package/src/mediaLibrary.ts +51 -0
- package/src/reducers/__tests__/auth.spec.ts +38 -0
- package/src/reducers/__tests__/collections.spec.js +571 -0
- package/src/reducers/__tests__/config.spec.js +38 -0
- package/src/reducers/__tests__/entries.spec.js +694 -0
- package/src/reducers/__tests__/entryDraft.spec.js +198 -0
- package/src/reducers/__tests__/globalUI.js +43 -0
- package/src/reducers/__tests__/integrations.spec.ts +76 -0
- package/src/reducers/__tests__/mediaLibrary.spec.js +154 -0
- package/src/reducers/__tests__/medias.spec.ts +49 -0
- package/src/reducers/auth.ts +46 -0
- package/src/reducers/collections.ts +483 -0
- package/src/reducers/combinedReducer.ts +11 -0
- package/src/reducers/config.ts +38 -0
- package/src/reducers/cursors.js +36 -0
- package/src/reducers/deploys.ts +52 -0
- package/src/reducers/editorialWorkflow.ts +163 -0
- package/src/reducers/entries.ts +806 -0
- package/src/reducers/entryDraft.js +218 -0
- package/src/reducers/globalUI.ts +45 -0
- package/src/reducers/index.ts +82 -0
- package/src/reducers/integrations.ts +59 -0
- package/src/reducers/mediaLibrary.ts +296 -0
- package/src/reducers/medias.ts +66 -0
- package/src/reducers/notifications.ts +53 -0
- package/src/reducers/search.ts +89 -0
- package/src/reducers/status.ts +40 -0
- package/src/redux/index.ts +18 -0
- package/src/redux/middleware/waitUntilAction.ts +64 -0
- package/src/routing/__tests__/history.spec.ts +49 -0
- package/src/routing/history.ts +17 -0
- package/src/types/diacritics.d.ts +1 -0
- package/src/types/global.d.ts +8 -0
- package/src/types/immutable.ts +39 -0
- package/src/types/redux.ts +810 -0
- package/src/types/tomlify-j0.4.d.ts +13 -0
- package/src/valueObjects/AssetProxy.ts +48 -0
- package/src/valueObjects/EditorComponent.js +38 -0
- package/src/valueObjects/Entry.ts +63 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.statusDescriptions = exports.status = exports.Statues = exports.SIMPLE = exports.EDITORIAL_WORKFLOW = void 0;
|
|
7
|
+
var _immutable = require("immutable");
|
|
8
|
+
// Create/edit workflow modes
|
|
9
|
+
const SIMPLE = 'simple';
|
|
10
|
+
exports.SIMPLE = SIMPLE;
|
|
11
|
+
const EDITORIAL_WORKFLOW = 'editorial_workflow';
|
|
12
|
+
exports.EDITORIAL_WORKFLOW = EDITORIAL_WORKFLOW;
|
|
13
|
+
const Statues = {
|
|
14
|
+
DRAFT: 'draft',
|
|
15
|
+
PENDING_REVIEW: 'pending_review',
|
|
16
|
+
PENDING_PUBLISH: 'pending_publish'
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// Available status
|
|
20
|
+
exports.Statues = Statues;
|
|
21
|
+
const status = (0, _immutable.OrderedMap)(Statues);
|
|
22
|
+
exports.status = status;
|
|
23
|
+
const statusDescriptions = (0, _immutable.Map)({
|
|
24
|
+
[status.get('DRAFT')]: 'Draft',
|
|
25
|
+
[status.get('PENDING_REVIEW')]: 'Waiting for Review',
|
|
26
|
+
[status.get('PENDING_PUBLISH')]: 'Waiting to go live'
|
|
27
|
+
});
|
|
28
|
+
exports.statusDescriptions = statusDescriptions;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.frontmatterFormats = exports.formatExtensions = exports.extensionFormatters = void 0;
|
|
7
|
+
exports.resolveFormat = resolveFormat;
|
|
8
|
+
var _get2 = _interopRequireDefault(require("lodash/get"));
|
|
9
|
+
var _immutable = require("immutable");
|
|
10
|
+
var _yaml = _interopRequireDefault(require("./yaml"));
|
|
11
|
+
var _toml = _interopRequireDefault(require("./toml"));
|
|
12
|
+
var _json = _interopRequireDefault(require("./json"));
|
|
13
|
+
var _frontmatter = require("./frontmatter");
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
const frontmatterFormats = ['yaml-frontmatter', 'toml-frontmatter', 'json-frontmatter'];
|
|
16
|
+
exports.frontmatterFormats = frontmatterFormats;
|
|
17
|
+
const formatExtensions = {
|
|
18
|
+
yml: 'yml',
|
|
19
|
+
yaml: 'yml',
|
|
20
|
+
toml: 'toml',
|
|
21
|
+
json: 'json',
|
|
22
|
+
frontmatter: 'md',
|
|
23
|
+
'json-frontmatter': 'md',
|
|
24
|
+
'toml-frontmatter': 'md',
|
|
25
|
+
'yaml-frontmatter': 'md'
|
|
26
|
+
};
|
|
27
|
+
exports.formatExtensions = formatExtensions;
|
|
28
|
+
const extensionFormatters = {
|
|
29
|
+
yml: _yaml.default,
|
|
30
|
+
yaml: _yaml.default,
|
|
31
|
+
toml: _toml.default,
|
|
32
|
+
json: _json.default,
|
|
33
|
+
md: _frontmatter.FrontmatterInfer,
|
|
34
|
+
markdown: _frontmatter.FrontmatterInfer,
|
|
35
|
+
html: _frontmatter.FrontmatterInfer
|
|
36
|
+
};
|
|
37
|
+
exports.extensionFormatters = extensionFormatters;
|
|
38
|
+
function formatByName(name, customDelimiter) {
|
|
39
|
+
return {
|
|
40
|
+
yml: _yaml.default,
|
|
41
|
+
yaml: _yaml.default,
|
|
42
|
+
toml: _toml.default,
|
|
43
|
+
json: _json.default,
|
|
44
|
+
frontmatter: _frontmatter.FrontmatterInfer,
|
|
45
|
+
'json-frontmatter': (0, _frontmatter.frontmatterJSON)(customDelimiter),
|
|
46
|
+
'toml-frontmatter': (0, _frontmatter.frontmatterTOML)(customDelimiter),
|
|
47
|
+
'yaml-frontmatter': (0, _frontmatter.frontmatterYAML)(customDelimiter)
|
|
48
|
+
}[name];
|
|
49
|
+
}
|
|
50
|
+
function frontmatterDelimiterIsList(frontmatterDelimiter) {
|
|
51
|
+
return _immutable.List.isList(frontmatterDelimiter);
|
|
52
|
+
}
|
|
53
|
+
function resolveFormat(collection, entry) {
|
|
54
|
+
// Check for custom delimiter
|
|
55
|
+
const frontmatter_delimiter = collection.get('frontmatter_delimiter');
|
|
56
|
+
const customDelimiter = frontmatterDelimiterIsList(frontmatter_delimiter) ? frontmatter_delimiter.toArray() : frontmatter_delimiter;
|
|
57
|
+
|
|
58
|
+
// If the format is specified in the collection, use that format.
|
|
59
|
+
const formatSpecification = collection.get('format');
|
|
60
|
+
if (formatSpecification) {
|
|
61
|
+
return formatByName(formatSpecification, customDelimiter);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// If a file already exists, infer the format from its file extension.
|
|
65
|
+
const filePath = entry && entry.path;
|
|
66
|
+
if (filePath) {
|
|
67
|
+
const fileExtension = filePath.split('.').pop();
|
|
68
|
+
if (fileExtension) {
|
|
69
|
+
return (0, _get2.default)(extensionFormatters, fileExtension);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// If creating a new file, and an `extension` is specified in the
|
|
74
|
+
// collection config, infer the format from that extension.
|
|
75
|
+
const extension = collection.get('extension');
|
|
76
|
+
if (extension) {
|
|
77
|
+
return (0, _get2.default)(extensionFormatters, extension);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// If no format is specified and it cannot be inferred, return the default.
|
|
81
|
+
return formatByName('frontmatter', customDelimiter);
|
|
82
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.FrontmatterInfer = exports.FrontmatterFormatter = void 0;
|
|
7
|
+
exports.frontmatterJSON = frontmatterJSON;
|
|
8
|
+
exports.frontmatterTOML = frontmatterTOML;
|
|
9
|
+
exports.frontmatterYAML = frontmatterYAML;
|
|
10
|
+
exports.getFormatOpts = getFormatOpts;
|
|
11
|
+
var _grayMatter = _interopRequireDefault(require("gray-matter"));
|
|
12
|
+
var _toml = _interopRequireDefault(require("./toml"));
|
|
13
|
+
var _yaml = _interopRequireDefault(require("./yaml"));
|
|
14
|
+
var _json = _interopRequireDefault(require("./json"));
|
|
15
|
+
const _excluded = ["body"];
|
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
18
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
19
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
20
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
21
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
22
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
23
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
24
|
+
const Languages = {
|
|
25
|
+
YAML: 'yaml',
|
|
26
|
+
TOML: 'toml',
|
|
27
|
+
JSON: 'json'
|
|
28
|
+
};
|
|
29
|
+
const parsers = {
|
|
30
|
+
toml: {
|
|
31
|
+
parse: input => _toml.default.fromFile(input),
|
|
32
|
+
stringify: (metadata, opts) => {
|
|
33
|
+
const {
|
|
34
|
+
sortedKeys
|
|
35
|
+
} = opts || {};
|
|
36
|
+
return _toml.default.toFile(metadata, sortedKeys);
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
json: {
|
|
40
|
+
parse: input => {
|
|
41
|
+
let JSONinput = input.trim();
|
|
42
|
+
// Fix JSON if leading and trailing brackets were trimmed.
|
|
43
|
+
if (JSONinput.slice(0, 1) !== '{') {
|
|
44
|
+
JSONinput = '{' + JSONinput + '}';
|
|
45
|
+
}
|
|
46
|
+
return _json.default.fromFile(JSONinput);
|
|
47
|
+
},
|
|
48
|
+
stringify: metadata => {
|
|
49
|
+
let JSONoutput = _json.default.toFile(metadata).trim();
|
|
50
|
+
// Trim leading and trailing brackets.
|
|
51
|
+
if (JSONoutput.slice(0, 1) === '{' && JSONoutput.slice(-1) === '}') {
|
|
52
|
+
JSONoutput = JSONoutput.slice(1, -1);
|
|
53
|
+
}
|
|
54
|
+
return JSONoutput;
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
yaml: {
|
|
58
|
+
parse: input => _yaml.default.fromFile(input),
|
|
59
|
+
stringify: (metadata, opts) => {
|
|
60
|
+
const {
|
|
61
|
+
sortedKeys,
|
|
62
|
+
comments
|
|
63
|
+
} = opts || {};
|
|
64
|
+
return _yaml.default.toFile(metadata, sortedKeys, comments);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
function inferFrontmatterFormat(str) {
|
|
69
|
+
const lineEnd = str.indexOf('\n');
|
|
70
|
+
const firstLine = str.slice(0, lineEnd !== -1 ? lineEnd : 0).trim();
|
|
71
|
+
if (firstLine.length > 3 && firstLine.slice(0, 3) === '---') {
|
|
72
|
+
// No need to infer, `gray-matter` will handle things like `---toml` for us.
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
switch (firstLine) {
|
|
76
|
+
case '---':
|
|
77
|
+
return getFormatOpts(Languages.YAML);
|
|
78
|
+
case '+++':
|
|
79
|
+
return getFormatOpts(Languages.TOML);
|
|
80
|
+
case '{':
|
|
81
|
+
return getFormatOpts(Languages.JSON);
|
|
82
|
+
default:
|
|
83
|
+
console.warn('Unrecognized front-matter format.');
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function getFormatOpts(format, customDelimiter) {
|
|
87
|
+
if (!format) {
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
const formats = {
|
|
91
|
+
yaml: {
|
|
92
|
+
language: Languages.YAML,
|
|
93
|
+
delimiters: '---'
|
|
94
|
+
},
|
|
95
|
+
toml: {
|
|
96
|
+
language: Languages.TOML,
|
|
97
|
+
delimiters: '+++'
|
|
98
|
+
},
|
|
99
|
+
json: {
|
|
100
|
+
language: Languages.JSON,
|
|
101
|
+
delimiters: ['{', '}']
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
const {
|
|
105
|
+
language,
|
|
106
|
+
delimiters
|
|
107
|
+
} = formats[format];
|
|
108
|
+
return {
|
|
109
|
+
language,
|
|
110
|
+
delimiters: customDelimiter || delimiters
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
class FrontmatterFormatter {
|
|
114
|
+
constructor(format, customDelimiter) {
|
|
115
|
+
_defineProperty(this, "format", void 0);
|
|
116
|
+
this.format = getFormatOpts(format, customDelimiter);
|
|
117
|
+
}
|
|
118
|
+
fromFile(content) {
|
|
119
|
+
const format = this.format || inferFrontmatterFormat(content);
|
|
120
|
+
const result = (0, _grayMatter.default)(content, _objectSpread({
|
|
121
|
+
engines: parsers
|
|
122
|
+
}, format));
|
|
123
|
+
// in the absent of a body when serializing an entry we use an empty one
|
|
124
|
+
// when calling `toFile`, so we don't want to add it when parsing.
|
|
125
|
+
return _objectSpread(_objectSpread({}, result.data), result.content.trim() && {
|
|
126
|
+
body: result.content
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
toFile(data, sortedKeys, comments) {
|
|
130
|
+
const {
|
|
131
|
+
body = ''
|
|
132
|
+
} = data,
|
|
133
|
+
meta = _objectWithoutProperties(data, _excluded);
|
|
134
|
+
|
|
135
|
+
// Stringify to YAML if the format was not set
|
|
136
|
+
const format = this.format || getFormatOpts(Languages.YAML);
|
|
137
|
+
|
|
138
|
+
// gray-matter always adds a line break at the end which trips our
|
|
139
|
+
// change detection logic
|
|
140
|
+
// https://github.com/jonschlinkert/gray-matter/issues/96
|
|
141
|
+
const trimLastLineBreak = body.slice(-1) !== '\n';
|
|
142
|
+
const file = _grayMatter.default.stringify(body, meta, _objectSpread({
|
|
143
|
+
engines: parsers,
|
|
144
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
145
|
+
// @ts-ignore `sortedKeys` is not recognized by gray-matter, so it gets passed through to the parser
|
|
146
|
+
sortedKeys,
|
|
147
|
+
comments
|
|
148
|
+
}, format));
|
|
149
|
+
return trimLastLineBreak && file.slice(-1) === '\n' ? file.slice(0, -1) : file;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
exports.FrontmatterFormatter = FrontmatterFormatter;
|
|
153
|
+
const FrontmatterInfer = new FrontmatterFormatter();
|
|
154
|
+
exports.FrontmatterInfer = FrontmatterInfer;
|
|
155
|
+
function frontmatterYAML(customDelimiter) {
|
|
156
|
+
return new FrontmatterFormatter(Languages.YAML, customDelimiter);
|
|
157
|
+
}
|
|
158
|
+
function frontmatterTOML(customDelimiter) {
|
|
159
|
+
return new FrontmatterFormatter(Languages.TOML, customDelimiter);
|
|
160
|
+
}
|
|
161
|
+
function frontmatterJSON(customDelimiter) {
|
|
162
|
+
return new FrontmatterFormatter(Languages.JSON, customDelimiter);
|
|
163
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.sortKeys = sortKeys;
|
|
7
|
+
function sortKeys(sortedKeys,
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
9
|
+
selector = a => a) {
|
|
10
|
+
return (a, b) => {
|
|
11
|
+
const idxA = sortedKeys.indexOf(selector(a));
|
|
12
|
+
const idxB = sortedKeys.indexOf(selector(b));
|
|
13
|
+
if (idxA === -1 || idxB === -1) return 0;
|
|
14
|
+
if (idxA > idxB) return 1;
|
|
15
|
+
if (idxA < idxB) return -1;
|
|
16
|
+
return 0;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _default = {
|
|
8
|
+
fromFile(content) {
|
|
9
|
+
return JSON.parse(content);
|
|
10
|
+
},
|
|
11
|
+
toFile(data) {
|
|
12
|
+
return JSON.stringify(data, null, 2);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
exports.default = _default;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _toml = _interopRequireDefault(require("@iarna/toml"));
|
|
8
|
+
var _tomlifyJ = _interopRequireDefault(require("tomlify-j0.4"));
|
|
9
|
+
var _moment = _interopRequireDefault(require("moment"));
|
|
10
|
+
var _AssetProxy = _interopRequireDefault(require("../valueObjects/AssetProxy"));
|
|
11
|
+
var _helpers = require("./helpers");
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
function outputReplacer(_key, value) {
|
|
14
|
+
if (_moment.default.isMoment(value)) {
|
|
15
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
16
|
+
// @ts-ignore
|
|
17
|
+
return value.format(value._f);
|
|
18
|
+
}
|
|
19
|
+
if (value instanceof _AssetProxy.default) {
|
|
20
|
+
return `${value.path}`;
|
|
21
|
+
}
|
|
22
|
+
if (typeof value === 'number' && Number.isInteger(value)) {
|
|
23
|
+
// Return the string representation of integers so tomlify won't render with tenths (".0")
|
|
24
|
+
return value.toString();
|
|
25
|
+
}
|
|
26
|
+
// Return `false` to use default (`undefined` would delete key).
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
var _default = {
|
|
30
|
+
fromFile(content) {
|
|
31
|
+
return _toml.default.parse(content);
|
|
32
|
+
},
|
|
33
|
+
toFile(data, sortedKeys = []) {
|
|
34
|
+
return _tomlifyJ.default.toToml(data, {
|
|
35
|
+
replace: outputReplacer,
|
|
36
|
+
sort: (0, _helpers.sortKeys)(sortedKeys)
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
exports.default = _default;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _yaml = _interopRequireDefault(require("yaml"));
|
|
8
|
+
var _helpers = require("./helpers");
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
function addComments(items, comments, prefix = '') {
|
|
11
|
+
items.forEach(item => {
|
|
12
|
+
if (item.key !== undefined) {
|
|
13
|
+
var _item$value;
|
|
14
|
+
const itemKey = item.key.toString();
|
|
15
|
+
const key = prefix ? `${prefix}.${itemKey}` : itemKey;
|
|
16
|
+
if (comments[key]) {
|
|
17
|
+
const value = comments[key].split('\\n').join('\n ');
|
|
18
|
+
item.commentBefore = ` ${value}`;
|
|
19
|
+
}
|
|
20
|
+
if (Array.isArray((_item$value = item.value) === null || _item$value === void 0 ? void 0 : _item$value.items)) {
|
|
21
|
+
addComments(item.value.items, comments, key);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
const timestampTag = {
|
|
27
|
+
identify: value => value instanceof Date,
|
|
28
|
+
default: true,
|
|
29
|
+
tag: '!timestamp',
|
|
30
|
+
test: RegExp('^' + '([0-9]{4})-([0-9]{2})-([0-9]{2})' +
|
|
31
|
+
// YYYY-MM-DD
|
|
32
|
+
'T' +
|
|
33
|
+
// T
|
|
34
|
+
'([0-9]{2}):([0-9]{2}):([0-9]{2}(\\.[0-9]+)?)' +
|
|
35
|
+
// HH:MM:SS(.ss)?
|
|
36
|
+
'Z' +
|
|
37
|
+
// Z
|
|
38
|
+
'$'),
|
|
39
|
+
resolve: str => new Date(str),
|
|
40
|
+
stringify: value => value.toISOString()
|
|
41
|
+
};
|
|
42
|
+
var _default = {
|
|
43
|
+
fromFile(content) {
|
|
44
|
+
if (content && content.trim().endsWith('---')) {
|
|
45
|
+
content = content.trim().slice(0, -3);
|
|
46
|
+
}
|
|
47
|
+
return _yaml.default.parse(content, {
|
|
48
|
+
customTags: [timestampTag]
|
|
49
|
+
});
|
|
50
|
+
},
|
|
51
|
+
toFile(data, sortedKeys = [], comments = {}) {
|
|
52
|
+
const contents = _yaml.default.createNode(data);
|
|
53
|
+
addComments(contents.items, comments);
|
|
54
|
+
contents.items.sort((0, _helpers.sortKeys)(sortedKeys, item => {
|
|
55
|
+
var _item$key;
|
|
56
|
+
return (_item$key = item.key) === null || _item$key === void 0 ? void 0 : _item$key.toString();
|
|
57
|
+
}));
|
|
58
|
+
const doc = new _yaml.default.Document();
|
|
59
|
+
doc.contents = contents;
|
|
60
|
+
return doc.toString();
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
exports.default = _default;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.DecapCmsCore = void 0;
|
|
7
|
+
var _bootstrap = _interopRequireDefault(require("./bootstrap"));
|
|
8
|
+
var _registry = _interopRequireDefault(require("./lib/registry"));
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
11
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
12
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
13
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
14
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
15
|
+
const DecapCmsCore = _objectSpread(_objectSpread({}, _registry.default), {}, {
|
|
16
|
+
init: _bootstrap.default
|
|
17
|
+
});
|
|
18
|
+
exports.DecapCmsCore = DecapCmsCore;
|
|
19
|
+
var _default = DecapCmsCore;
|
|
20
|
+
exports.default = _default;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getIntegrationProvider = void 0;
|
|
7
|
+
exports.resolveIntegrations = resolveIntegrations;
|
|
8
|
+
var _immutable = require("immutable");
|
|
9
|
+
var _implementation = _interopRequireDefault(require("./providers/algolia/implementation"));
|
|
10
|
+
var _implementation2 = _interopRequireDefault(require("./providers/assetStore/implementation"));
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
function resolveIntegrations(interationsConfig, getToken) {
|
|
13
|
+
let integrationInstances = (0, _immutable.Map)({});
|
|
14
|
+
interationsConfig.get('providers').forEach((providerData, providerName) => {
|
|
15
|
+
switch (providerName) {
|
|
16
|
+
case 'algolia':
|
|
17
|
+
integrationInstances = integrationInstances.set('algolia', new _implementation.default(providerData));
|
|
18
|
+
break;
|
|
19
|
+
case 'assetStore':
|
|
20
|
+
integrationInstances = integrationInstances.set('assetStore', new _implementation2.default(providerData, getToken));
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
return integrationInstances;
|
|
25
|
+
}
|
|
26
|
+
const getIntegrationProvider = function () {
|
|
27
|
+
let integrations = null;
|
|
28
|
+
return (interationsConfig, getToken, provider) => {
|
|
29
|
+
if (integrations) {
|
|
30
|
+
return integrations.get(provider);
|
|
31
|
+
} else {
|
|
32
|
+
integrations = resolveIntegrations(interationsConfig, getToken);
|
|
33
|
+
return integrations.get(provider);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}();
|
|
37
|
+
exports.getIntegrationProvider = getIntegrationProvider;
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _flatten2 = _interopRequireDefault(require("lodash/flatten"));
|
|
8
|
+
var _decapCmsLibUtil = require("decap-cms-lib-util");
|
|
9
|
+
var _Entry = require("../../../valueObjects/Entry");
|
|
10
|
+
var _collections = require("../../../reducers/collections");
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
13
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
14
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
15
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
16
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
17
|
+
const {
|
|
18
|
+
fetchWithTimeout: fetch
|
|
19
|
+
} = _decapCmsLibUtil.unsentRequest;
|
|
20
|
+
function getSlug(path) {
|
|
21
|
+
return path.split('/').pop().replace(/\.[^.]+$/, '');
|
|
22
|
+
}
|
|
23
|
+
class Algolia {
|
|
24
|
+
constructor(config) {
|
|
25
|
+
this.config = config;
|
|
26
|
+
if (config.get('applicationID') == null || config.get('apiKey') == null) {
|
|
27
|
+
throw 'The Algolia search integration needs the credentials (applicationID and apiKey) in the integration configuration.';
|
|
28
|
+
}
|
|
29
|
+
this.applicationID = config.get('applicationID');
|
|
30
|
+
this.apiKey = config.get('apiKey');
|
|
31
|
+
const prefix = config.get('indexPrefix');
|
|
32
|
+
this.indexPrefix = prefix ? `${prefix}-` : '';
|
|
33
|
+
this.searchURL = `https://${this.applicationID}-dsn.algolia.net/1`;
|
|
34
|
+
this.entriesCache = {
|
|
35
|
+
collection: null,
|
|
36
|
+
page: null,
|
|
37
|
+
entries: []
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
requestHeaders(headers = {}) {
|
|
41
|
+
return _objectSpread({
|
|
42
|
+
'X-Algolia-API-Key': this.apiKey,
|
|
43
|
+
'X-Algolia-Application-Id': this.applicationID,
|
|
44
|
+
'Content-Type': 'application/json'
|
|
45
|
+
}, headers);
|
|
46
|
+
}
|
|
47
|
+
parseJsonResponse(response) {
|
|
48
|
+
return response.json().then(json => {
|
|
49
|
+
if (!response.ok) {
|
|
50
|
+
return Promise.reject(json);
|
|
51
|
+
}
|
|
52
|
+
return json;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
urlFor(path, options) {
|
|
56
|
+
const params = [];
|
|
57
|
+
if (options.params) {
|
|
58
|
+
for (const key in options.params) {
|
|
59
|
+
params.push(`${key}=${encodeURIComponent(options.params[key])}`);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (params.length) {
|
|
63
|
+
path += `?${params.join('&')}`;
|
|
64
|
+
}
|
|
65
|
+
return path;
|
|
66
|
+
}
|
|
67
|
+
request(path, options = {}) {
|
|
68
|
+
const headers = this.requestHeaders(options.headers || {});
|
|
69
|
+
const url = this.urlFor(path, options);
|
|
70
|
+
return fetch(url, _objectSpread(_objectSpread({}, options), {}, {
|
|
71
|
+
headers
|
|
72
|
+
})).then(response => {
|
|
73
|
+
const contentType = response.headers.get('Content-Type');
|
|
74
|
+
if (contentType && contentType.match(/json/)) {
|
|
75
|
+
return this.parseJsonResponse(response);
|
|
76
|
+
}
|
|
77
|
+
return response.text();
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
search(collections, searchTerm, page) {
|
|
81
|
+
const searchCollections = collections.map(collection => ({
|
|
82
|
+
indexName: `${this.indexPrefix}${collection}`,
|
|
83
|
+
params: `query=${searchTerm}&page=${page}`
|
|
84
|
+
}));
|
|
85
|
+
return this.request(`${this.searchURL}/indexes/*/queries`, {
|
|
86
|
+
method: 'POST',
|
|
87
|
+
body: JSON.stringify({
|
|
88
|
+
requests: searchCollections
|
|
89
|
+
})
|
|
90
|
+
}).then(response => {
|
|
91
|
+
const entries = response.results.map((result, index) => result.hits.map(hit => {
|
|
92
|
+
const slug = getSlug(hit.path);
|
|
93
|
+
return (0, _Entry.createEntry)(collections[index], slug, hit.path, {
|
|
94
|
+
data: hit.data,
|
|
95
|
+
partial: true
|
|
96
|
+
});
|
|
97
|
+
}));
|
|
98
|
+
return {
|
|
99
|
+
entries: (0, _flatten2.default)(entries),
|
|
100
|
+
pagination: page
|
|
101
|
+
};
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
searchBy(field, collection, query) {
|
|
105
|
+
return this.request(`${this.searchURL}/indexes/${this.indexPrefix}${collection}`, {
|
|
106
|
+
params: {
|
|
107
|
+
restrictSearchableAttributes: field,
|
|
108
|
+
query
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
listEntries(collection, page) {
|
|
113
|
+
if (this.entriesCache.collection === collection && this.entriesCache.page === page) {
|
|
114
|
+
return Promise.resolve({
|
|
115
|
+
page: this.entriesCache.page,
|
|
116
|
+
entries: this.entriesCache.entries
|
|
117
|
+
});
|
|
118
|
+
} else {
|
|
119
|
+
return this.request(`${this.searchURL}/indexes/${this.indexPrefix}${collection.get('name')}`, {
|
|
120
|
+
params: {
|
|
121
|
+
page
|
|
122
|
+
}
|
|
123
|
+
}).then(response => {
|
|
124
|
+
const entries = response.hits.map(hit => {
|
|
125
|
+
const slug = (0, _collections.selectEntrySlug)(collection, hit.path);
|
|
126
|
+
return (0, _Entry.createEntry)(collection.get('name'), slug, hit.path, {
|
|
127
|
+
data: hit.data,
|
|
128
|
+
partial: true
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
this.entriesCache = {
|
|
132
|
+
collection,
|
|
133
|
+
pagination: response.page,
|
|
134
|
+
entries
|
|
135
|
+
};
|
|
136
|
+
return {
|
|
137
|
+
entries,
|
|
138
|
+
pagination: response.page
|
|
139
|
+
};
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
async listAllEntries(collection) {
|
|
144
|
+
const params = {
|
|
145
|
+
hitsPerPage: 1000
|
|
146
|
+
};
|
|
147
|
+
let response = await this.request(`${this.searchURL}/indexes/${this.indexPrefix}${collection.get('name')}`, {
|
|
148
|
+
params
|
|
149
|
+
});
|
|
150
|
+
let {
|
|
151
|
+
nbPages = 0,
|
|
152
|
+
hits,
|
|
153
|
+
page
|
|
154
|
+
} = response;
|
|
155
|
+
page = page + 1;
|
|
156
|
+
while (page < nbPages) {
|
|
157
|
+
response = await this.request(`${this.searchURL}/indexes/${this.indexPrefix}${collection.get('name')}`, {
|
|
158
|
+
params: _objectSpread(_objectSpread({}, params), {}, {
|
|
159
|
+
page
|
|
160
|
+
})
|
|
161
|
+
});
|
|
162
|
+
hits = [...hits, ...response.hits];
|
|
163
|
+
page = page + 1;
|
|
164
|
+
}
|
|
165
|
+
const entries = hits.map(hit => {
|
|
166
|
+
const slug = (0, _collections.selectEntrySlug)(collection, hit.path);
|
|
167
|
+
return (0, _Entry.createEntry)(collection.get('name'), slug, hit.path, {
|
|
168
|
+
data: hit.data,
|
|
169
|
+
partial: true
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
return entries;
|
|
173
|
+
}
|
|
174
|
+
getEntry(collection, slug) {
|
|
175
|
+
return this.searchBy('slug', collection.get('name'), slug).then(response => {
|
|
176
|
+
const entry = response.hits.filter(hit => hit.slug === slug)[0];
|
|
177
|
+
return (0, _Entry.createEntry)(collection.get('name'), slug, entry.path, {
|
|
178
|
+
data: entry.data,
|
|
179
|
+
partial: true
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
exports.default = Algolia;
|