Revert "fix: safely extract notebook summaries"

This reverts commit fa3d0375c5.
This commit is contained in:
ajnart committed 2026-08-14 11:32:09 +02:00
1 parent cd8773681f
commit f8b364dce2
3 files changed
+13 -53

No files matched your search

+13 -18
View File
@@ -1,38 +1,33 @@
"use client";
import dynamic from "next/dynamic";
import { useEffect, useState } from "react";
import { useScopedI18n } from "@homarr/translation/client";
import { WidgetMobileSummary } from "../common/mobile-summary";
import type { WidgetComponentProps } from "../definition";
import { extractNotebookExcerpt } from "./mobile-summary";
const Notebook = dynamic(() => import("./notebook").then((module) => module.Notebook), {
ssr: false,
});
interface NotebookMobileSummaryProps {
content: string;
label: string;
}
const NotebookMobileSummary = ({ content, label }: NotebookMobileSummaryProps) => {
const [excerpt, setExcerpt] = useState("");
useEffect(() => {
setExcerpt(extractNotebookExcerpt(content));
}, [content]);
return <WidgetMobileSummary value={excerpt || "—"} label={label} />;
};
export default function NotebookWidget(props: WidgetComponentProps<"notebook">) {
const t = useScopedI18n("widget.notebook");
if (props.displayMode === "mobileSummary") {
return <NotebookMobileSummary content={props.options.content} label={t("name")} />;
const excerpt = props.options.content
.replace(/<style\b[^>]*>[\s\S]*?<\/style>/gi, " ")
.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gi, " ")
.replace(/<[^>]+>/g, " ")
.replace(/&(?:nbsp|#160);/gi, " ")
.replace(/&(?:amp|#38);/gi, "&")
.replace(/&(?:lt|#60);/gi, "<")
.replace(/&(?:gt|#62);/gi, ">")
.replace(/&(?:quot|#34);/gi, '"')
.replace(/\s+/g, " ")
.trim();
return <WidgetMobileSummary value={excerpt || "—"} label={t("name")} />;
}
return <Notebook {...props} />;