Skip to content

Commit

Permalink
Merge pull request #1203 from EcrituresNumeriques/fix/1195
Browse files Browse the repository at this point in the history
  • Loading branch information
thom4parisot authored Jan 26, 2025
2 parents 4c33714 + 1da0efe commit ccf746f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
6 changes: 3 additions & 3 deletions front/src/components/Preview.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ query getArticle($id: ID!, $version: ID!, $hasVersion: Boolean!) {
workingVersion @skip(if: $hasVersion) {
md
bib
metadata
yaml(options: { strip_markdown: true })
}
}

version(version: $version) @include(if: $hasVersion) {
name
md
bib
metadata
yaml(options: { strip_markdown: true })
}
}

Expand All @@ -44,7 +44,7 @@ query getCorpus($filter: FilterCorpusInput) {
workingVersion {
md
bib
metadata
yaml(options: { strip_markdown: true })
}
}
}
Expand Down
18 changes: 12 additions & 6 deletions front/src/components/Preview.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useEffect, useMemo } from 'react'
import { useParams } from 'react-router-dom'
import { Loading } from '@geist-ui/core'
import { useStyloExportPreview } from '../hooks/stylo-export.js'
import { toYaml } from './Write/metadata/yaml.js'
import useGraphQL from '../hooks/graphql.js'
import { applicationConfig } from '../config.js'

Expand Down Expand Up @@ -29,7 +30,7 @@ const strategies = new Map([
const root = data?.article?.workingVersion ?? data?.version
return {
md_content: root?.md,
metadata_content: root?.metadata,
yaml_content: root?.yaml,
bib_content: root?.bib,
}
},
Expand All @@ -55,17 +56,22 @@ const strategies = new Map([
},
mapContent(data) {
return data?.corpus?.at(0)?.articles?.reduce(
(obj, { article }) => ({
(obj, { article }, index) => ({
md_content: obj.md_content + '\n\n\n' + article.workingVersion.md,
metadata_content: Object.keys(obj.metadata_content).length
? { ...data.corpus.metadata, ...obj.metadata_content }
: article.workingVersion.metadata,
yaml_content:
index === 0
? toYaml(data.corpus.medatada) +
'\n\n---\n\n' +
article.workingVersion.yaml
: obj.yaml_content +
'\n\n---\n\n' +
article.workingVersion.yaml,
bib_content:
obj.bib_content + '\n\n---\n\n' + article.workingVersion.bib,
}),
{
md_content: '',
metadata_content: {},
yaml_content: '',
bib_content: '',
}
)
Expand Down
20 changes: 13 additions & 7 deletions front/src/hooks/stylo-export.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { useMemo } from 'react'
import useSWR from 'swr'
import { toYaml } from '../components/Write/metadata/yaml.js'
import { applicationConfig } from '../config.js'

const fetcher = (url) => fetch(url).then((response) => response.json())
Expand Down Expand Up @@ -47,19 +45,27 @@ export default function useStyloExport({ bibliography_style, bib: excerpt }) {
}
}

/**
*
* @param {{
* md_content: string,
* bib_content: string,
* yaml_content: string,
* with_toc?: boolean,
* with_nocite?: boolean,
* with_link_citations?: boolean
* }} StyloExportPreviewParams
* @returns {Promise<{ html: string, isLoading: boolean }}
*/
export function useStyloExportPreview({
md_content,
bib_content,
metadata_content,
yaml_content,
with_toc = false,
with_nocite = false,
with_link_citations = false,
}) {
const { pandocExportEndpoint } = applicationConfig
const yaml_content = useMemo(
() => toYaml(metadata_content),
[metadata_content]
)
const previewArgs = {
bibliography_style: 'chicagomodified',
md_content,
Expand Down

0 comments on commit ccf746f

Please sign in to comment.