Skip to content

Commit

Permalink
cite website as workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
garethbilaney committed Nov 24, 2024
1 parent 76da365 commit adc4771
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/content/docs/converters/website.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ sidebar_position: 5
---
import UrlInputComponent from "./website"

<UrlInputComponent />
<UrlInputComponent client:only="react" />
7 changes: 6 additions & 1 deletion src/content/docs/converters/website.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const UrlInputComponent: React.FC = () => {
const [metadata, setMetadata] = useState<Metadata | null>(null);
const [error, setError] = useState<string | null>(null);
const [useBibLaTeX, setUseBibLaTeX] = useState<boolean>(false);
const [loading, setLoading] = useState<boolean>(false);

const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
setUrl(event.target.value);
Expand All @@ -34,6 +35,7 @@ const UrlInputComponent: React.FC = () => {
setError(null);

try {
setLoading(true)
const response = await fetch(`https://api.microlink.io?url=${url}`);

if (!response.ok) {
Expand All @@ -50,8 +52,9 @@ const UrlInputComponent: React.FC = () => {
author: data.data.author,
year: data.data.date,
};

setMetadata(metadata);
setLoading(false)
} catch (error) {
setError('Failed to extract metadata');
}
Expand Down Expand Up @@ -100,10 +103,12 @@ const UrlInputComponent: React.FC = () => {
</label>
</div>
{error && <p style={{ color: 'red' }}>{error}</p>}
{loading && <p style={{ color: 'green' }}>{"Loading"}</p>}
{metadata && (
<div>
<h3>{useBibLaTeX ? 'BibLaTeX Entry' : 'BibTeX Entry'}:</h3>
<pre>{useBibLaTeX ? formatBibLaTeX(metadata) : formatBibTeX(metadata)}</pre>

</div>
)}
</div>
Expand Down

0 comments on commit adc4771

Please sign in to comment.