Files
lume/packages/utils/src/parser.ts
雨宮蓮 a4aef25adb final design (#184)
* feat: redesign

* feat: update other columns to new design

* chore: small fixes

* fix: better manage external webview

* feat: redesign note

* feat: update ui

* chore: update

* chore: update

* chore: polish ui

* chore: update auth ui

* feat: finalize note design

* chore: small fixes

* feat: add window management in rust

* chore: format

* feat: update ui for event screen

* feat: update event screen

* feat: final
2024-05-03 15:15:48 +07:00

36 lines
678 B
TypeScript

import { IMAGES, VIDEOS } from "./constants";
export function parser(content: string) {
// Get clean content
const urls = content.match(/(https?:\/\/\S+)/gi);
// Extract images and videos from content
const images: string[] = [];
const videos: string[] = [];
let text: string = content;
if (urls) {
for (const url of urls) {
const ext = new URL(url).pathname.split(".")[1];
if (IMAGES.includes(ext)) {
text = text.replace(url, "");
images.push(url);
}
if (VIDEOS.includes(ext)) {
text = text.replace(url, "");
videos.push(url);
}
}
}
const trimContent = text.trim();
return {
content: trimContent,
images,
videos,
};
}