Skip to content
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
8 changes: 8 additions & 0 deletions datagouv-components/src/config.ts
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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<Dataset, 'resources' | 'community_resources'>, resource: Resource | CommunityResource) => string
}

export const configKey = Symbol() as InjectionKey<PluginConfig>
Expand Down
3 changes: 3 additions & 0 deletions datagouv-components/src/functions/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ export function isCommunityResource(resource: Resource | CommunityResource): boo
}

export function getResourceExternalUrl(dataset: Dataset | DatasetV2 | Omit<Dataset, 'resources' | 'community_resources'>, 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}`
}

Expand Down
Loading