Skip to content
Snippets Groups Projects
Commit 6b24a2a0 authored by Remi  PLANEL's avatar Remi PLANEL
Browse files

Resolve "Document zotero process"

parent 0825f083
No related branches found
No related tags found
1 merge request!23Resolve "Document zotero process"
......@@ -52,6 +52,20 @@ stages:
# when: on_success
# expire_in: "30 days"
get-zotero:
image: python:3.11-bullseye
stage: get-data
before_script:
- apt update
- pip install pyzotero
script:
- ./scripts/get-articles.py -k ${ZOTERO_API_KEY}
- mv articles.json public/
artifacts:
paths:
- public/articles.json
get-pfam:
image: ubuntu:23.04
stage: get-data
......
# Content v2 Minimal Starter
# Knowledge database of information about defense systems in prokaryotes
## How to use references in the wiki pages
You can add article references by providing a doi directly in the markdown files.
There is two syntaxes that won't do exactly the same thing.
You can add the doi in the [front-matter](https://content.nuxt.com/usage/markdown#front-matter) like :
```yaml
relevantAbstracts:
- doi: 10.1016/j.mib.2005.06.006
- doi: 10.1023/A:1002027321171
```
or directly in the content of the page using:
```md
:ref{doi=10.1023/A:1002027321171}
```
In both cases, before the page is rendered, these doi are parsed, the associated metadatas are automatically fetched and displayed at the bottom of the page like:
![references](/public/readme/references.png)
When using the `:ref{doi=10.1023/A:1002027321171}` syntax, a link is added like `(Barrangou et al, 2017)`
## Article metadata source
They come from a local file [articles.json](public/articles.json). This file is automatically generated during each run of the production [deployment pipeline](/.gitlab-ci.yml) from a [Zotero collection](https://www.zotero.org/groups/5151022/mdmlab/collections/BSWL96X3) using the script [get-articles.py](/scripts/get-articles.py). If the doi is not found in this file, [crossref](https://api.crossref.org/) is used as fallback.
## How can we update the [Zotero collection](https://www.zotero.org/groups/5151022/mdmlab/collections/BSWL96X3)
Whoever belongs to the MDM Zotero group can update it.
For person external, you can create an [issue](https://gitlab.pasteur.fr/mdm-lab/wiki/-/issues/new) that list at least doi you want to add.
## Contributing
Look at the [Content documentation](https://content-v2.nuxtjs.org/) to learn more.
## Setup
### Setup
Make sure to install the dependencies:
......@@ -17,15 +54,15 @@ npm install
pnpm install
```
## Development Server
### Development Server
Start the development server on http://localhost:3000
Start the development server on <http://localhost:3000>
```bash
npm run dev
```
## Production
### Production
Build the application for production:
......
......@@ -19,10 +19,10 @@ const { mobile } = useDisplay();
const show = ref(false);
const articleTitle = computed(() => {
return props?.title ?? article.value?.title ?? props.doi;
return props?.title ?? article?.value?.title ?? props.doi;
});
const articleAbstract = computed(() => {
return props.abstract ?? article.value?.abstract;
return props.abstract ?? article?.value?.abstract;
});
</script>
<template>
......
......@@ -16,7 +16,7 @@ const doiBaseUrl = ref(new URL("https://doi.org/"));
const fetchedDoi = ref(
await Promise.all(
props.items.map(async (doi) => {
const url = new URL(`/works/${doi}`, " https://api.crossref.org/").href;
const url = new URL(`/works/${doi}`, "https://api.crossref.org/").href;
const { data, error } = await useFetchVueUse<{
message: {
DOI: string;
......
import { useArticlesStore } from '@/stores/articles'
import { ref, computed, watchEffect, queryContent } from '#imports'
import { CslJson } from '@/stores/articles'
import { useArticlesStore, CslJson } from '../stores/articles'
import { ref, computed, watchEffect, toValue } from "vue"
// import { useFetch } from '#app';
// import { useFetch } from "nuxt"
export interface ArticleMessage {
DOI: string;
......@@ -48,7 +48,6 @@ export function useFetchArticle(doi: string) {
const pending = ref(false)
const doiBaseUrl = ref(new URL("https://doi.org/"));
const url = ref(new URL(`/works/${doi}`, " https://api.crossref.org/").href);
const article = computed(() => {
if (srcArticle.value != undefined) {
const {
......@@ -86,29 +85,50 @@ export function useFetchArticle(doi: string) {
} else { return srcArticle.value }
})
const zoteroArticles = ref([])
// const config = useRuntimeConfig()
// console.log(config.value)
const fetchLocalArticles = () => {
useFetch<RawArticle[]>(
"/articles.json",
{ lazy: true, server: false }
).then(({ data }) => {
zoteroArticles.value = data.value
}) // localPending.value = articlesPending.value
if (zoteroArticles.value?.length > 0) {
for (const article of zoteroArticles.value) {
// console.log("article files : ", article.DOI)
store.add(article)
}
}
watchEffect(async () => {
}
if (store.articles.size === 0) {
const localArticles = await queryContent('/_partials/_articles').where({ _partial: true }).findOne()
if (localArticles?.articles && store.articles.size <= 0) {
for (const article of localArticles.articles) {
store.add(article)
}
const fetchCrossRef = () => {
useFetch<RawArticle>(toValue(url), {
lazy: true, server: false,
}).then(({ data, pending: pendingUseFetch }) => {
if (data.value?.message) {
srcArticle.value = data.value.message
}
pending.value = pendingUseFetch.value
})
}
watchEffect(() => {
// no article in the store
if (store.articles.size === 0) {
fetchLocalArticles()
}
if (store.articles.has(doi)) {
srcArticle.value = store.articles.get(doi)
return
} else {
const { data, pending: pendingUseFetch, error, refresh } = await useFetch<RawArticle>(toValue(url), {
lazy: true, server: false,
})
if (data.value?.message) {
srcArticle.value = data.value.message
}
pending.value = pendingUseFetch.value
fetchCrossRef()
}
})
......@@ -124,4 +144,6 @@ export function useFetchArticle(doi: string) {
return new URL(doi, doiBaseUrl.value).href;
}
return { article, pending }
}
\ No newline at end of file
}
Source diff could not be displayed: it is too large. Options to address this: view the blob.
public/readme/references.png

146 KiB

#!/usr/bin/env python3
from pyzotero import zotero
import json
import argparse
parser = argparse.ArgumentParser(
prog="get-articles",
description="get articles from zotero collection",
)
parser.add_argument("-k", "--key", type=str) # option that takes a value
args = parser.parse_args()
zot = zotero.Zotero("5151022", "group", args.key)
collection = zot.collection("BSWL96X3")
tot_items = collection["meta"]["numItems"]
batch_size = 100
def get_articles(tot_items, batch_size):
starts = range(0, tot_items, batch_size)
for i in starts:
items = zot.collection_items(
"BSWL96X3",
format="csljson",
limit=batch_size,
start=i,
itemType="journalArticle",
)["items"]
for item in items:
yield item
items = list(get_articles(tot_items, batch_size))
json_object = json.dumps(items, indent=2)
with open("articles.json", "w") as outfile:
outfile.write(json_object)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment