Skip to content

Commit

Permalink
Fix #210 - Make sure file name is always checked to exclude _index.md
Browse files Browse the repository at this point in the history
  • Loading branch information
kyoshino committed Sep 29, 2024
1 parent a1537d2 commit a08ef99
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/lib/services/assets/parser.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getPathInfo } from '@sveltia/utils/file';
import { getAssetKind } from '$lib/services/assets';

/**
Expand All @@ -10,7 +11,6 @@ export const parseAssetFiles = (assetFiles) =>
const {
file,
path,
name = /** @type {string} */ (path.split('/').pop()),
sha,
size,
text = undefined,
Expand All @@ -22,10 +22,10 @@ export const parseAssetFiles = (assetFiles) =>
file,
blobURL: undefined,
path,
name,
name: getPathInfo(path).basename,
sha,
size,
kind: getAssetKind(name),
kind: getAssetKind(path),
text,
folder: internalPath,
...meta,
Expand Down
16 changes: 5 additions & 11 deletions src/lib/services/backends/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,24 +237,18 @@ const getAllFiles = async () => {
await iterate(_rootDirHandle);

return Promise.all(
availableFileList.map(async ({ file, path }) => {
availableFileList.map(async ({ file, path: rawPath }) => {
const { name, size } = file;
// The file path must be normalized, as certain non-ASCII characters (e.g. Japanese) can be
// problematic particularly on macOS
const path = rawPath.normalize();

const [sha, text] = await Promise.all([
getHash(file),
name.match(/\.(?:json|markdown|md|toml|ya?ml)$/i) ? readAsText(file) : undefined,
]);

// Both the file path and name should be normalized, as certain non-ASCII (Japanese)
// characters can be problematic particularly on macOS
return {
file,
path: path.normalize(),
name: name.normalize(),
sha,
size,
text,
};
return { file, path, sha, size, text };
}),
);
};
Expand Down
3 changes: 1 addition & 2 deletions src/lib/services/contents/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,6 @@ export const parseEntryFiles = (entryFiles) => {
}

const {
name,
path,
sha,
meta = {},
Expand Down Expand Up @@ -338,7 +337,7 @@ export const parseEntryFiles = (entryFiles) => {
// Skip Hugo’s special index page that shouldn’t appear in a folder collection, unless the
// collection’s `path` ends with `_index` and the extension is `md`.
if (
name === '_index.md' &&
getPathInfo(path).basename === '_index.md' &&
!(collection.path?.split('/').pop() === '_index' && extension === 'md') &&
!fileName
) {
Expand Down
1 change: 0 additions & 1 deletion src/lib/typedefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@
* @typedef {object} BaseFileListItem
* @property {'entry' | 'asset'} [type] - File type handled in the CMS.
* @property {File} [file] - File object. Local backend only.
* @property {string} [name] - File name.
* @property {string} path - File path.
* @property {string} sha - SHA-1 hash for the file.
* @property {number} [size] - File size in bytes.
Expand Down

0 comments on commit a08ef99

Please sign in to comment.