Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken links in sources modal #3050

Merged
merged 2 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,30 @@ export const makeUnitConversionFactor = ({
export const makeLinks = ({ link }: { link?: string }): React.ReactNode => {
if (!link) return null
const linkFragments = splitSourceTextIntoFragments(link)
return (
<>
{linkFragments.map((text, index) => (
<>
<span>
<SimpleMarkdownText text={text} useParagraphs={false} />
</span>
{index < linkFragments.length - 1 && <br />}
</>
))}
</>
)
return linkFragments.map((urlOrText, index) => {
const isUrl = urlOrText.startsWith("http") && !urlOrText.match(/\s/)
return (
<React.Fragment key={urlOrText}>
<span>
{isUrl ? (
<a
href={urlOrText}
target="_blank"
rel="noopener noreferrer"
>
{urlOrText}
</a>
) : (
<SimpleMarkdownText
text={urlOrText}
useParagraphs={false}
/>
)}
</span>
{index < linkFragments.length - 1 && <br />}
</React.Fragment>
)
})
}

const getDateRange = (dateRange: string): string | null => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { DisplaySource, uniqBy, formatSourceDate } from "@ourworldindata/utils"
import { SimpleMarkdownText } from "../SimpleMarkdownText.js"
import { CodeSnippet } from "../CodeSnippet/CodeSnippet.js"
import { REUSE_THIS_WORK_SECTION_ID } from "../SharedDataPageConstants.js"
import { makeLinks } from "../IndicatorKeyData/IndicatorKeyData.js"

export interface IndicatorSourcesProps {
sources: DisplaySource[]
Expand Down Expand Up @@ -128,10 +129,7 @@ const SourceContent = (props: {
Retrieved from
</div>
<div className="source-key-data__content">
<SimpleMarkdownText
text={source.retrievedFrom}
useParagraphs={false}
/>
{makeLinks({ link: source.retrievedFrom })}
</div>
</div>
)}
Expand Down
Loading