Skip to content

Commit

Permalink
data-page-better-citations
Browse files Browse the repository at this point in the history
  • Loading branch information
danyx23 committed Oct 23, 2023
1 parent 15c5b28 commit 9b54071
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 24 deletions.
1 change: 1 addition & 0 deletions packages/@ourworldindata/utils/src/owidTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1602,6 +1602,7 @@ export interface DataPageV2ContentFields {
faqEntries: FaqEntryData | undefined
// TODO: add gdocs for FAQs
isPreviewing?: boolean
canonicalUrl: string
}

export interface UserCountryInformation {
Expand Down
1 change: 1 addition & 0 deletions site/DataPageV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export const DataPageV2 = (props: {
grapherConfig={grapherConfig}
isPreviewing={isPreviewing}
faqEntries={faqEntries}
canonicalUrl={canonicalUrl}
/>
</DebugProvider>
</div>
Expand Down
69 changes: 46 additions & 23 deletions site/DataPageV2Content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import {
slugify,
DATAPAGE_SOURCES_AND_PROCESSING_SECTION_ID,
EnrichedBlockList,
uniq,
pick,
capitalize,
getWindowUrl,

Check warning on line 20 in site/DataPageV2Content.tsx

View workflow job for this annotation

GitHub Actions / eslint

'getWindowUrl' is defined but never used. Allowed unused vars must match /^_/u

Check warning on line 20 in site/DataPageV2Content.tsx

View workflow job for this annotation

GitHub Actions / eslint

'getWindowUrl' is defined but never used. Allowed unused vars must match /^_/u
} from "@ourworldindata/utils"
import { markdownToEnrichedTextBlock } from "@ourworldindata/components"
import { AttachmentsContext, DocumentContext } from "./gdocs/OwidGdoc.js"
Expand Down Expand Up @@ -92,6 +96,7 @@ export const DataPageV2Content = ({
grapherConfig,
isPreviewing = false,
faqEntries,
canonicalUrl,
}: DataPageV2ContentFields & {
grapherConfig: GrapherInterface
}) => {
Expand Down Expand Up @@ -145,26 +150,44 @@ export const DataPageV2Content = ({
// TODO: this is missing the attribution field ATM and
// so assembles something only roughly similar to the citation described
// by Joe. Also, we need the dataset title.
const producers = datapageData.origins.map((o) => o.producer).join("; ")
const origins = uniq(
datapageData.origins.map((item) =>
pick(item, [
"producer",
"descriptionSnapshot",
"dateAccessed",
"urlMain",
"description",
"citationFull",
])
)
)
const producers = uniq(datapageData.origins.map((o) => o.producer)).join(
"; "
)
const attributionLong = datapageData.attribution ?? producers
// const attributionShort =
// datapageData.attributionShort ??
// uniq(
// datapageData.origins.map((o) => o.attributionShort ?? o.producer)
// ).join("; ")
const processedAdapted =
datapageData.owidProcessingLevel === "minor" ? `minor` : `major`
const lastUpdated = dayjs(datapageData.lastUpdated, ["YYYY", "YYYY-MM-DD"])
const yearOfUpdate = lastUpdated.year()
const citationShort = `${producers} — with ${processedAdapted} processing by Our World In Data (${yearOfUpdate})`
const originsLong = datapageData.origins
.map((o) => `${o.producer}, ${o.title ?? o.titleSnapshot}`)
.join("; ")
const dateAccessed =
datapageData.origins &&
datapageData.origins.length &&
datapageData.origins[0].dateAccessed
? dayjs(datapageData.origins[0].dateAccessed).format("MMMM D, YYYY")
: ""
const urlAccessed =
datapageData.origins &&
datapageData.origins.length &&
datapageData.origins[0].urlDownload
const citationLong = `${citationShort}. ${datapageData.title}. ${originsLong}, ${processedAdapted} by Our World In Data. Retrieved ${dateAccessed} from ${urlAccessed}`
const citationShort = `${attributionLong} — with ${processedAdapted} processing by Our World In Data (${yearOfUpdate})`
const originsLong = uniq(
datapageData.origins.map(
(o) => `${o.producer}, ${o.title ?? o.titleSnapshot}`
)
).join("; ")
const today = dayjs().format("MMMM D, YYYY")
const currentYear = dayjs().year()
const citationLong = `${citationShort}. ${
datapageData.title
}. ${originsLong}. ${capitalize(
processedAdapted
)} processing by Our World In Data. Retrieved ${today} from ${canonicalUrl}`

const {
linkedDocuments = {},
Expand Down Expand Up @@ -204,7 +227,7 @@ export const DataPageV2Content = ({

const dateRange = getDateRange(datapageData.dateRange)

const citationDatapage = `Our World In Data (${yearOfUpdate}). Data Page: ${datapageData.title}${producers}. Retrieved from {url} [online resource]`
const citationDatapage = `Our World In Data (${currentYear}). Data Page: ${datapageData.title}${producers}. Retrieved from ${canonicalUrl} [online resource]`
return (
<AttachmentsContext.Provider
value={{
Expand Down Expand Up @@ -553,14 +576,14 @@ export const DataPageV2Content = ({
>
Sources and processing
</h2>
{datapageData.origins.length > 0 && (
{origins.length > 0 && (
<div className="data-sources grid span-cols-12">
<h3 className="data-sources__heading span-cols-2 span-lg-cols-3 col-md-start-2 span-md-cols-10 col-sm-start-1 span-sm-cols-12">
This data is based on the following
sources
</h3>
<div className="col-start-4 span-cols-6 col-lg-start-5 span-lg-cols-7 col-md-start-2 span-md-cols-10 col-sm-start-1 span-sm-cols-12">
{datapageData.origins.map(
{origins.map(
(
source,
idx: number,
Expand Down Expand Up @@ -597,7 +620,7 @@ export const DataPageV2Content = ({
/>
)}
{(source.dateAccessed ||
source.urlDownload) && (
source.urlMain) && (
<div
className="grid source__key-data"
style={{
Expand All @@ -618,7 +641,7 @@ export const DataPageV2Content = ({
</div>
</div>
)}
{source.urlDownload && (
{source.urlMain && (
<div className="key-data key-data--hide-overflow">
<div className="key-data__title--dark">
Retrieved
Expand All @@ -627,13 +650,13 @@ export const DataPageV2Content = ({
<div>
<a
href={
source.urlDownload
source.urlMain
}
target="_blank"
rel="noreferrer"
>
{
source.urlDownload
source.urlMain
}
</a>
</div>
Expand Down
2 changes: 1 addition & 1 deletion site/ExpandableToggle.scss
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
}

.ExpandableToggle__content--teaser {
height: 48px;
height: 96px;
-webkit-mask-image: linear-gradient(180deg, #000 0%, transparent);
}

Expand Down

0 comments on commit 9b54071

Please sign in to comment.