-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
164 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use tauri::regex::Regex; | ||
|
||
pub(crate) fn extract_og_property(body: &str, pattern: &str) -> Result<String, String> { | ||
let re = Regex::new(pattern).map_err(|e| format!("{e:?}"))?; | ||
let property = re | ||
.captures(body) | ||
.and_then(|captures| captures.get(1)) | ||
.map(|m| m.as_str()) | ||
.map(String::from) | ||
.ok_or("regex not found")?; | ||
|
||
Ok(property) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { Box, Button, Card, CardActionArea, CardActions, CardContent, CardMedia, Link, Typography } from "@mui/material"; | ||
import "./styles/UserInfo.css"; | ||
import "./styles/common.css" | ||
import { useEffect, useMemo, useState } from "react"; | ||
import { invoke } from "@tauri-apps/api"; | ||
import { s } from "@tauri-apps/api/app-373d24a3"; | ||
|
||
interface UrlPreviewProps { | ||
href: string; | ||
} | ||
|
||
|
||
interface UrlPreviewData { | ||
title: string, | ||
description: string, | ||
image: string | ||
} | ||
|
||
function UrlPreview(props: UrlPreviewProps) { | ||
|
||
let [urlPreviewData, setUrlPreviewData] = useState<UrlPreviewData | undefined>(undefined); | ||
|
||
useEffect(() => { | ||
invoke<string>('get_open_graph_data_from_website', { url: props.href }).then((data) => { | ||
setUrlPreviewData(JSON.parse(data)); | ||
}); | ||
}, []); | ||
|
||
const createOpenGraphData = useMemo(() => { | ||
console.log(urlPreviewData); | ||
if (urlPreviewData) { | ||
return ( | ||
<Card sx={{ maxWidth: 345 }}> | ||
<CardActionArea onClick={() => window.open(props.href, '_blank')}> | ||
<CardMedia | ||
component="img" | ||
height="140" | ||
image={urlPreviewData.image} | ||
alt={urlPreviewData.title} | ||
/> | ||
<CardContent> | ||
<Typography gutterBottom variant="h5" component="div"> | ||
{urlPreviewData.title} | ||
</Typography> | ||
<Typography variant="body2" color="text.secondary"> | ||
{urlPreviewData.description} | ||
</Typography> | ||
</CardContent> | ||
</CardActionArea> | ||
<CardActions> | ||
<Button size="small" color="primary" href={props.href} target="_blank" sx={{fontSize: 9, textTransform: 'lowercase'}}> | ||
{props.href} | ||
</Button> | ||
</CardActions> | ||
</Card> | ||
) | ||
} else { | ||
return ( | ||
<Box> | ||
<Link href={props.href}>{props.href}</Link> | ||
</Box> | ||
); | ||
} | ||
}, [urlPreviewData]); | ||
|
||
return ( | ||
<Box> | ||
{createOpenGraphData} | ||
</Box> | ||
); | ||
} | ||
|
||
export default UrlPreview; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,28 @@ | ||
/* listen for the return message once the tweet has been loaded */ | ||
window.addEventListener("message", (event) => { | ||
if (event.origin !== "https://twitframe.com") return; | ||
|
||
const { element, height } = event.data; | ||
element.style.height = `${height}px`; | ||
}); | ||
|
||
export function createEmbeddedIFrame(url: string): Node { | ||
const iframe = document.createElement('iframe'); | ||
iframe.src = url; | ||
iframe.style.minWidth = '480px'; | ||
iframe.style.minHeight = '270px'; | ||
iframe.style.border = 'none'; | ||
iframe.style.background = 'transparent'; | ||
iframe.style.colorScheme = 'auto'; | ||
iframe.className = 'embedded-iframe'; | ||
iframe.allowFullscreen = true; | ||
return iframe; | ||
} | ||
|
||
iframe.onload = (el) => { | ||
console.log("iframe loaded", el); | ||
//iframe.contentWindow?.postMessage({ element: el.target, query: "height" }, | ||
// "https://twitframe.com"); | ||
} | ||
|
||
|
||
return iframe; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.