Last two week, I created share feed for ChatChaft in CloudFlare, this week, I tried to optimize it:
Refine the Feed Icon
At first, I just copied the URL after user clicking the Feed Icon on the header, but it is not a good way to show it to users. So I change it to open a new tab.
const currentUrl = window.location.href;
const parsedUrl = new URL(currentUrl);
const userFeedUrl = `${parsedUrl.origin}/api/share/${user.username}/feed.atom`;
window.open(userFeedUrl, "_blank");
The Endeavor to Parse HTML with Linkedom
Last week, I used cheerio to parse HTML on cloudflare, but it was published 2 years ago and hasn't seen updates since that.
So I try to find a better one library. I turn to use linkedom to parse HTML on cloudflare:
const document = new DOMParser().parseFromString(chatContent, "text/html");
const getTitle = document.querySelector('meta[property="og:title"]');
const title = getTitle ? getTitle.getAttribute("content") : "No Title";
const getSummary = document.querySelector('meta[property="og:description"]');
const summary = getSummary ? getSummary.getAttribute("content") : "No Summary";
const getUrl = document.querySelector('meta[property="og:url"]');
const url = getUrl ? getUrl.getAttribute("content") : "No URL";
const preContentElement = document.querySelector("pre");
const preContent = preContentElement ? preContentElement.textContent : "";
here I check getTitle first which can solve the some document don't have title sometimes.
Conclusion
I think I've finished the feed feature and we almost finish this semester, next week I'll make a conclusion of what I've done this semester on ChatCraft project.
Top comments (0)