mirror of
https://github.com/DefectingCat/DefectingCat.github.io
synced 2025-07-15 16:51:37 +00:00
add url previewer in post content
This commit is contained in:
@ -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;
|
||||
});
|
||||
|
@ -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);
|
||||
};
|
||||
|
Reference in New Issue
Block a user