Skip to content

Commit 29c2094

Browse files
committed
Use the first H1 in the body if there isn’t an explicit title
1 parent dd736d1 commit 29c2094

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/project/types/website/website-search.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,21 @@ export async function updateSearchIndex(
187187
const doc = new DOMParser().parseFromString(contents, "text/html")!;
188188

189189
// determine title
190-
const titleEl = doc.querySelector("h1.title");
190+
const findTitle = () => {
191+
const titleEl = doc.querySelector("h1.title");
192+
if (titleEl) {
193+
return titleEl;
194+
} else {
195+
const title = doc.querySelector("main h1");
196+
if (title) {
197+
return title;
198+
} else {
199+
return undefined;
200+
}
201+
}
202+
};
203+
204+
const titleEl = findTitle();
191205
const title = titleEl
192206
? titleEl.textContent
193207
: (websiteTitle(context.config) || "");

0 commit comments

Comments
 (0)