Skip to content

Commit

Permalink
Remove unnecessary store
Browse files Browse the repository at this point in the history
  • Loading branch information
kyoshino committed Dec 19, 2024
1 parent 0a70916 commit 8d47aac
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 12 deletions.
3 changes: 1 addition & 2 deletions src/lib/services/contents/file/format.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as TOML from 'smol-toml';
import { get } from 'svelte/store';
import YAML from 'yaml';
import { customFileFormats } from '$lib/services/contents/file';

Expand Down Expand Up @@ -41,7 +40,7 @@ const formatYAML = (obj, { yamlQuote = false } = {}) =>
*/
export const formatEntryFile = async ({ content, _file }) => {
const { format, fmDelimiters, yamlQuote = false } = _file;
const customFormatter = get(customFileFormats)[format]?.formatter;
const customFormatter = customFileFormats[format]?.formatter;

if (customFormatter) {
return `${(await customFormatter(content)).trim()}\n`;
Expand Down
7 changes: 3 additions & 4 deletions src/lib/services/contents/file/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { getPathInfo } from '@sveltia/utils/file';
import { escapeRegExp, stripSlashes } from '@sveltia/utils/string';
import { get, writable } from 'svelte/store';

/**
* @type {import('svelte/store').Writable<Record<string, CustomFileFormat>>}
* @type {Record<string, CustomFileFormat>}
*/
export const customFileFormats = writable({});
export const customFileFormats = {};

/**
* Detect a file extension from the given entry file configuration.
Expand All @@ -17,7 +16,7 @@ export const customFileFormats = writable({});
* @see https://decapcms.org/docs/configuration-options/#extension-and-format
*/
const detectFileExtension = ({ extension, format, path }) => {
const customExtension = format ? get(customFileFormats)[format]?.extension : undefined;
const customExtension = format ? customFileFormats[format]?.extension : undefined;

if (customExtension) {
return customExtension;
Expand Down
3 changes: 1 addition & 2 deletions src/lib/services/contents/file/parse.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { toRaw } from '@sveltia/utils/object';
import { escapeRegExp } from '@sveltia/utils/string';
import * as TOML from 'smol-toml';
import { get } from 'svelte/store';
import YAML from 'yaml';
import { customFileFormats, getFrontMatterDelimiters } from '$lib/services/contents/file';
import { getCollection } from '$lib/services/contents/collection';
Expand Down Expand Up @@ -72,7 +71,7 @@ export const parseEntryFile = async ({ text = '', path, folder: { collectionName
} = collectionFile ?? /** @type {EntryCollection} */ (collection);

const format = _format === 'frontmatter' ? detectFrontMatterFormat(text) : _format;
const customParser = get(customFileFormats)[format]?.parser;
const customParser = customFileFormats[format]?.parser;

if (customParser) {
return customParser(text);
Expand Down
5 changes: 1 addition & 4 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,7 @@ const init = async ({ config = {} } = {}) => {
* @see https://decapcms.org/docs/custom-formatters/
*/
const registerCustomFormat = (name, extension, { fromFile, toFile }) => {
customFileFormats.update((formats) => ({
...formats,
[name]: { extension, parser: fromFile, formatter: toFile },
}));
customFileFormats[name] = { extension, parser: fromFile, formatter: toFile };
};

/**
Expand Down

0 comments on commit 8d47aac

Please sign in to comment.