alinea
Version:
[](https://npmjs.org/package/alinea) [](https://packagephobia.com/result?p=alinea)
61 lines (59 loc) • 1.83 kB
JavaScript
import "../../chunks/chunk-U5RRZUYZ.js";
// src/core/util/EntryRows.ts
import { JsonLoader } from "alinea/backend";
import { createFileHash, createRowHash } from "alinea/backend/util/ContentHash";
import * as paths from "alinea/core/util/Paths";
import { entryFilepath, entryInfo, entryUrl } from "../EntryFilenames.js";
import { createRecord } from "../EntryRecord.js";
import { EntryPhase } from "../EntryRow.js";
import { Root } from "../Root.js";
async function createEntryRow(config, input) {
const record = createRecord(input);
const fileContents = JsonLoader.format(config.schema, record);
const fileHash = await createFileHash(fileContents);
const rowHash = await createRowHash({ ...input, fileHash });
return { ...input, fileHash, rowHash };
}
function entryParentPaths(config, entry) {
const root = Root.data(config.workspaces[entry.workspace][entry.root]);
return entry.parentDir.split("/").filter(Boolean).slice(root.i18n ? 1 : 0);
}
function publishEntryRow(config, entry) {
const path = entry.data.path;
const parentPaths = entryParentPaths(config, entry);
const filePath = entryFilepath(
config,
{
...entry,
path,
phase: EntryPhase.Published
},
parentPaths
);
const parentDir = paths.dirname(filePath);
const extension = paths.extname(filePath);
const fileName = paths.basename(filePath, extension);
const [entryPath] = entryInfo(fileName);
const childrenDir = paths.join(parentDir, entryPath);
const urlMeta = {
locale: entry.locale,
path,
phase: entry.phase,
parentPaths
};
const url = entryUrl(config.schema[entry.type], urlMeta);
return {
...entry,
phase: EntryPhase.Published,
path,
filePath,
parentDir,
childrenDir,
url
};
}
export {
createEntryRow,
entryParentPaths,
publishEntryRow
};