diff --git a/datagouv-components/src/config.ts b/datagouv-components/src/config.ts index 896dc1c98..b05826500 100644 --- a/datagouv-components/src/config.ts +++ b/datagouv-components/src/config.ts @@ -1,6 +1,8 @@ import { inject, type Component, type InjectionKey } from 'vue' import type { UseFetchFunction } from './functions/api.types' import type { $Fetch, FetchOptions } from 'ofetch' +import type { Dataset, DatasetV2 } from './types/datasets' +import type { CommunityResource, Resource } from './types/resources' export type PluginConfig = { name: string // Name of the application (ex: data.gouv.fr) @@ -45,6 +47,12 @@ export type PluginConfig = { clientOnly?: Component | null searchDebounce?: number forumUrl?: string + /** + * Overrides the "Copier le lien" target built by `getResourceExternalUrl`. + * Must return an absolute URL: it is copied to the clipboard and used as an + * external, `_blank` link target. + */ + getResourceExternalUrl?: (dataset: Dataset | DatasetV2 | Omit, resource: Resource | CommunityResource) => string } export const configKey = Symbol() as InjectionKey diff --git a/datagouv-components/src/functions/resources.ts b/datagouv-components/src/functions/resources.ts index 3e0b17c1e..9d1d8e5c8 100644 --- a/datagouv-components/src/functions/resources.ts +++ b/datagouv-components/src/functions/resources.ts @@ -176,6 +176,9 @@ export function isCommunityResource(resource: Resource | CommunityResource): boo } export function getResourceExternalUrl(dataset: Dataset | DatasetV2 | Omit, resource: Resource | CommunityResource): string { + const config = useComponentsConfig() + if (config.getResourceExternalUrl) return config.getResourceExternalUrl(dataset, resource) + return `${dataset.page}${isCommunityResource(resource) ? '/community-resources' : ''}?resource_id=${resource.id}` }