Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 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,8 @@ export type PluginConfig = {
clientOnly?: Component | null
searchDebounce?: number
forumUrl?: string
/** Overrides the "Copier le lien" target built by `getResourceExternalUrl`. */
resourceExternalUrl?: (dataset: Dataset | DatasetV2 | Omit<Dataset, 'resources' | 'community_resources'>, resource: Resource | CommunityResource) => string
Comment thread
abulte marked this conversation as resolved.
Outdated
}

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.resourceExternalUrl) return config.resourceExternalUrl(dataset, resource)

return `${dataset.page}${isCommunityResource(resource) ? '/community-resources' : ''}?resource_id=${resource.id}`
}

Expand Down
Loading