Enable BibTeX export
This commit is contained in:
parent
442484438e
commit
6fd3a94fac
4 changed files with 54 additions and 8 deletions
|
@ -83,11 +83,7 @@ export const loadAllAuthors = (): Promise<{ [key: string]: Author }> => {
|
||||||
|
|
||||||
worker.postMessage('LOAD')
|
worker.postMessage('LOAD')
|
||||||
} else {
|
} else {
|
||||||
reject(
|
return
|
||||||
new Error(
|
|
||||||
'Web Workers are not supported in this environment. Please avoid using a prehistoric browser.'
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import {
|
||||||
import { ItemBadge, Status } from '@/app/components/Badges'
|
import { ItemBadge, Status } from '@/app/components/Badges'
|
||||||
import { notFound } from 'next/navigation'
|
import { notFound } from 'next/navigation'
|
||||||
import VersionChooser from './VersionChooser'
|
import VersionChooser from './VersionChooser'
|
||||||
|
import crypto from 'crypto'
|
||||||
|
|
||||||
const zillaSlab = Zilla_Slab({ subsets: ['latin'], weight: ['500'] })
|
const zillaSlab = Zilla_Slab({ subsets: ['latin'], weight: ['500'] })
|
||||||
|
|
||||||
|
@ -32,6 +33,13 @@ const DocumentViewer = ({ slug }: Readonly<{ slug: string }>) => {
|
||||||
status,
|
status,
|
||||||
} = manifest
|
} = manifest
|
||||||
|
|
||||||
|
// git style hash
|
||||||
|
const hash = crypto
|
||||||
|
.createHash('sha256')
|
||||||
|
.update(slug)
|
||||||
|
.digest('hex')
|
||||||
|
.substring(0, 7)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='max-w-4xl lg:max-w-6xl mx-auto'>
|
<div className='max-w-4xl lg:max-w-6xl mx-auto'>
|
||||||
<h1
|
<h1
|
||||||
|
@ -78,7 +86,7 @@ const DocumentViewer = ({ slug }: Readonly<{ slug: string }>) => {
|
||||||
</p>
|
</p>
|
||||||
<p className='my-2'>
|
<p className='my-2'>
|
||||||
<span className='font-bold'>Cite as: </span>
|
<span className='font-bold'>Cite as: </span>
|
||||||
{citation ? <>{citation}</> : <>eeXiv:{slug}</>}
|
{citation ? <>{citation}</> : <>eeXiv:{hash}</>}
|
||||||
</p>
|
</p>
|
||||||
<VersionChooser doc={doc} slug={slug} />
|
<VersionChooser doc={doc} slug={slug} />
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -2,13 +2,28 @@
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import { Document } from '@/app/db/data'
|
import { Document } from '@/app/db/data'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
|
import { loadAllAuthors } from '@/app/db/loaders'
|
||||||
|
import { useSuspenseQuery } from '@tanstack/react-query'
|
||||||
|
import { epoch2date } from '@/app/utils/epoch2datestring'
|
||||||
|
|
||||||
const VersionChooser = ({
|
const VersionChooser = ({
|
||||||
doc,
|
doc,
|
||||||
slug,
|
slug,
|
||||||
}: Readonly<{ doc: Document; slug: string }>) => {
|
}: Readonly<{ doc: Document; slug: string }>) => {
|
||||||
|
const { data, error } = useSuspenseQuery({
|
||||||
|
queryKey: ['authors_all'],
|
||||||
|
queryFn: () => {
|
||||||
|
const data = loadAllAuthors()
|
||||||
|
return data
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if (error) throw error
|
||||||
|
|
||||||
|
let authorList = data
|
||||||
|
|
||||||
const { file } = doc
|
const { file } = doc
|
||||||
const { latest } = doc.manifest
|
const { authors, latest } = doc.manifest
|
||||||
|
const date = epoch2date(doc.manifest.dates[doc.manifest.dates.length - 1])
|
||||||
|
|
||||||
const fileEnding = file === 'other' ? '' : `.${file}`
|
const fileEnding = file === 'other' ? '' : `.${file}`
|
||||||
const [selectedRevision, setSelectedRevision] = useState<number>(latest) // Initialize the selected revision with the latest revision
|
const [selectedRevision, setSelectedRevision] = useState<number>(latest) // Initialize the selected revision with the latest revision
|
||||||
|
@ -31,8 +46,31 @@ const VersionChooser = ({
|
||||||
})()}
|
})()}
|
||||||
</button>
|
</button>
|
||||||
</Link>
|
</Link>
|
||||||
|
<button
|
||||||
|
className='ml-2 h-10 px-2.5 bg-slate-300 rounded-md'
|
||||||
|
onClick={() => {
|
||||||
|
const bibtex = `@article{
|
||||||
|
author={${
|
||||||
|
authors.map((a: string, i) => {
|
||||||
|
const author = authorList[a].name.first + ' ' + authorList[a].name.last
|
||||||
|
if (i === 0) return author
|
||||||
|
else if (i === authors.length - 1) return ` and ${author}`
|
||||||
|
else return `, ${author}`
|
||||||
|
}).join('')
|
||||||
|
}},
|
||||||
|
title={${doc.manifest.title}},
|
||||||
|
journal={eeXiv journal},
|
||||||
|
year={${date.getFullYear()}},
|
||||||
|
month={${date.toLocaleString('default', { month: 'short' })}},
|
||||||
|
url={${window.location.href}}
|
||||||
|
}`
|
||||||
|
navigator.clipboard.writeText(bibtex)
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Export BibTeX
|
||||||
|
</button>
|
||||||
<select
|
<select
|
||||||
className='ml-2 p-2.5 bg-slate-300 rounded-md'
|
className='ml-2 h-10 px-2.5 bg-slate-300 rounded-md'
|
||||||
value={`v${selectedRevision}`}
|
value={`v${selectedRevision}`}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
setSelectedRevision(parseInt(e.target.value.replace(/\D/g, ''), 10))
|
setSelectedRevision(parseInt(e.target.value.replace(/\D/g, ''), 10))
|
||||||
|
|
|
@ -11,3 +11,7 @@ export function epoch2datestring(epoch: number): string {
|
||||||
|
|
||||||
return formattedDate
|
return formattedDate
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function epoch2date(epoch: number): Date {
|
||||||
|
return new Date(epoch * 1000)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue