1
0
Fork 0
mirror of https://github.com/kou029w/quot.git synced 2025-01-18 16:08:03 +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",
"compilerOptions": {
"lib": ["dom", "dom.iterable"],
"lib": ["esnext", "dom", "dom.iterable"],
"jsx": "react-jsx",
"jsxImportSource": "solid-js/h",
"noPropertyAccessFromIndexSignature": false

View file

@ -43,14 +43,23 @@ export default (props: {
editor.registerUpdateListener(() =>
editor.update(() => {
const root = $getRoot();
const lines = root.getChildren().map((line, i) => {
if (i === 0) return line.getTextContent().trim();
const defaultTitle = new Date()
.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;
return `${" ".repeat(indent)}${line.getTextContent()}`;
});
const title = lines[0];
const text = lines.join("\n");
props.onUpdatePage({ id: props.id, title: title ?? "", text });
const text = [title, ...lines].join("\n");
props.onUpdatePage({ id: props.id, title, text });
})
)
);