tickle/modules/utils/getFirstTitleContent.mjs

13 lines
378 B
JavaScript
Raw Permalink Normal View History

2023-05-09 02:00:53 +00:00
/**
* Returns the first title content in the document, if there is one.
* @param {Node} content
* @returns
*/
export const getFirstTitleContent = (content = document) => {
/** @type {HTMLHeadElement} */
const firstTitleElement = content.querySelector("h1");
return firstTitleElement ? firstTitleElement.textContent || "" : "";
};
export default getFirstTitleContent;