2023-10-02 23:10:49 +03:00
|
|
|
import Mustache from "mustache";
|
|
|
|
|
import {stripHtml} from "../../helpers";
|
|
|
|
|
|
|
|
|
|
export function previewTitle(schemas, record, graph) {
|
2023-10-26 17:45:23 +03:00
|
|
|
let schema = schemas.find((aSchema) => aSchema.name === record?.schema);
|
2024-08-19 17:48:10 +03:00
|
|
|
if (!schema?.cardTitle) {
|
2023-10-02 23:10:49 +03:00
|
|
|
return noTemplate(schema, record);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let recordData = record.data;
|
2024-08-19 17:48:10 +03:00
|
|
|
let render = Mustache.render(schema.cardTitle, recordData);
|
2023-10-02 23:10:49 +03:00
|
|
|
if (!render || render === "") {
|
|
|
|
|
return noTemplate(schema, record);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return stripHtml(render.slice(0, 300));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function noTemplate(schema, record) {
|
|
|
|
|
if (schema?.type === "files") {
|
2024-08-17 20:31:04 +03:00
|
|
|
return record._file.path;
|
2023-10-02 23:10:49 +03:00
|
|
|
}
|
2023-10-26 17:45:23 +03:00
|
|
|
|
|
|
|
|
let title = stripHtml(
|
2023-10-02 23:10:49 +03:00
|
|
|
record?.data[schema.fields.filter((f) => f.info.name === "text")[0]?.name]
|
|
|
|
|
).slice(0, 300);
|
2023-10-26 17:45:23 +03:00
|
|
|
|
2024-08-18 19:20:53 +03:00
|
|
|
if(title.trim() === ""){
|
2024-07-22 20:09:16 +03:00
|
|
|
return "~Untitled~";
|
2023-10-26 17:45:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return title;
|
2023-10-02 23:10:49 +03:00
|
|
|
}
|