1
0
Fork 0
mirror of https://github.com/kou029w/quot.git synced 2025-01-19 00:18:09 +00:00

set default title

This commit is contained in:
Nebel 2022-09-07 17:48:18 +09:00
parent 6e1ef081b8
commit b569dac9ce
2 changed files with 15 additions and 6 deletions

View file

@ -1,7 +1,7 @@
{ {
"extends": "@tsconfig/node18-strictest-esm/tsconfig.json", "extends": "@tsconfig/node18-strictest-esm/tsconfig.json",
"compilerOptions": { "compilerOptions": {
"lib": ["dom", "dom.iterable"], "lib": ["esnext", "dom", "dom.iterable"],
"jsx": "react-jsx", "jsx": "react-jsx",
"jsxImportSource": "solid-js/h", "jsxImportSource": "solid-js/h",
"noPropertyAccessFromIndexSignature": false "noPropertyAccessFromIndexSignature": false

View file

@ -43,14 +43,23 @@ export default (props: {
editor.registerUpdateListener(() => editor.registerUpdateListener(() =>
editor.update(() => { editor.update(() => {
const root = $getRoot(); const root = $getRoot();
const lines = root.getChildren().map((line, i) => { const defaultTitle = new Date()
if (i === 0) return line.getTextContent().trim(); .toLocaleDateString(navigator.language, {
year: "numeric",
month: "2-digit",
day: "2-digit",
})
.replaceAll("/", "-");
const [titleNode, ...lineNodes] = root.getChildren();
const title =
titleNode?.getTextContent().trim() ||
(lineNodes.length === 0 ? "" : defaultTitle);
const lines = lineNodes.map((line) => {
const indent = $isElementNode(line) ? line.getIndent() : 0; const indent = $isElementNode(line) ? line.getIndent() : 0;
return `${" ".repeat(indent)}${line.getTextContent()}`; return `${" ".repeat(indent)}${line.getTextContent()}`;
}); });
const title = lines[0]; const text = [title, ...lines].join("\n");
const text = lines.join("\n"); props.onUpdatePage({ id: props.id, title, text });
props.onUpdatePage({ id: props.id, title: title ?? "", text });
}) })
) )
); );