Add new document properties and search options

This commit is contained in:
Team 1280 Programming Laptop 2024-02-15 15:11:34 -08:00
parent 7d49198552
commit 79f74d8731
5 changed files with 28 additions and 10 deletions

View file

@ -26,6 +26,7 @@ export interface Document {
abstract: string
file: FileType
citation?: string
doi?: string
}
export interface DocumentManifest {
title: string
@ -282,6 +283,7 @@ On Day 1 we will discuss the ins and outs of the robot. The Electrical Sub team
},
abstract: `In this paper, we present eeXiv, an open-source, open-access project hosted by Team 1280 EECS ("Electrical Engineering and Computer Science"), independent of the department of the same name at UC Berkeley. We aim to rival arXiv as the single largest open-source and open-access research paper repository and as the largest research paper repository on the West Coast, transforming San Ramon Valley High School into a tier-1 research institution. Similar to arXiv, we host electronic preprints and postprints (known as e-prints) approved for posting after a rigorous peer review process. Our repository consists of scientific papers in the fields of mathematics, physics, astronomy, electrical engineering, computer science, quantitative biology, statistics, mathematical finance, and economics, with a focus on papers specific to the FIRST Robotics Competition. eeXiv bypasses the traditional bureaucracy of research publication, which involves lengthy peer review proesses and journal approval, by enabling "libre" and "open" publication, dissemination, and consumption of research artifacts. `,
file: 'pdf',
doi: '10.5281/zenodo.10668656',
},
}

View file

@ -11,6 +11,7 @@ import {
import { ItemBadge, Status } from '@/app/components/Badges'
import VersionChooser from './VersionChooser'
import crypto from 'crypto'
import generateHash from '@/app/utils/hash'
import { Suspense } from 'react'
import { loadDocument } from '@/app/db/loaders'
import { useSuspenseQuery } from '@tanstack/react-query'
@ -28,7 +29,7 @@ const DocumentViewer = ({ slug }: Readonly<{ slug: string }>) => {
if (error) throw error
let doc = data
const { manifest, abstract, citation } = doc
const { manifest, abstract, citation, doi } = doc
const {
title,
@ -44,11 +45,7 @@ const DocumentViewer = ({ slug }: Readonly<{ slug: string }>) => {
} = manifest
// git style hash
const hash = crypto
.createHash('sha256')
.update(slug)
.digest('hex')
.substring(0, 7)
const hash = generateHash(slug)
return (
<div className='max-w-4xl lg:max-w-6xl mx-auto'>
@ -98,6 +95,12 @@ const DocumentViewer = ({ slug }: Readonly<{ slug: string }>) => {
<span className='font-bold'>Cite as: </span>
{citation ? <>{citation}</> : <>eeXiv:{hash}</>}
</p>
{doi && (
<p className='my-2'>
<span className='font-bold'>DOI: </span>
{doi}
</p>
)}
<Suspense
fallback={
<div className='max-w-sm animate-pulse flex flex-wrap gap-2'>

View file

@ -74,10 +74,7 @@ export default function Home() {
the fields of physics, mathematics, computer science, quantitative
biology, quantitative finance, statistics, electrical engineering and
systems science, and economics, but mainly related to the{' '}
<Link
href='./topic/frc'
target='_blank'
>
<Link href='./topic/frc' target='_blank'>
FIRST Robotics Competition (FRC)
</Link>
. Materials on this site may be published independently through other

10
src/app/utils/hash.ts Normal file
View file

@ -0,0 +1,10 @@
import crypto from 'crypto'
export default function hash(key: string) {
// git style hash
return crypto
.createHash('sha256')
.update(key)
.digest('hex')
.substring(0, 7)
}

View file

@ -1,6 +1,8 @@
import { documents, authors, affiliations, topics } from '@/app/db/data'
import MiniSearch from 'minisearch'
import { CustomSearchResult } from './searchDocs'
import crypto from 'crypto'
import hash from './hash'
// converting the documents object into an array that can be index by minisearch
const docs = Object.entries(documents).map(([key, value]) => ({
@ -34,6 +36,8 @@ const docs = Object.entries(documents).map(([key, value]) => ({
)
.join(' '),
key: key,
citation: value.citation ? value.citation : hash(key),
doi: value.doi ? value.doi : undefined,
}))
const miniSearch = new MiniSearch({
@ -45,6 +49,8 @@ const miniSearch = new MiniSearch({
'title',
'type',
'affiliations',
'citation',
'doi',
],
storeFields: ['key', 'abstract', 'manifest'],
searchOptions: {