add url previewer in post content

This commit is contained in:
DefectingCat
2024-01-04 11:23:01 +08:00
parent 14c99275f7
commit d5607c0105
6 changed files with 120 additions and 7 deletions

View File

@ -132,3 +132,25 @@ export const getSignalGist = cache(async (id: string) => {
return data;
});
export interface LinkResult {
meta: Meta;
links: Link[];
rel: [];
}
export interface Link {
href: string;
rel: string[];
type: string;
}
export interface Meta {
description: string;
title: string;
author: string;
canonical: string;
}
export const urlMeta = cache(async (url: string) => {
return (await (
await fetch(`http://iframely.server.crestify.com/iframely?url=${url}`)
).json()) as LinkResult;
});

View File

@ -152,3 +152,10 @@ export const frameArea = (
// point the camera to look at the center of the box
camera.lookAt(boxCenter.x, boxCenter.y, boxCenter.z);
};
export const isUrl = (url: string) => {
const urlRegex = new RegExp(
'^(http:\\/\\/www\\.|https:\\/\\/www\\.|http:\\/\\/|https:\\/\\/)?[a-z0-9]+([\\-.]{1}[a-z0-9]+)*\\.[a-z]{2,5}(:[0-9]{1,5})?(\\/.*)?$',
);
return urlRegex.test(url);
};