Skip to content

Commit fe40935

Browse files
Merge pull request #11 from opendata-swiss/dataset-detail-markdown
use external link component in markdown
2 parents 1a2387d + 95d734c commit fe40935

File tree

8 files changed

+79
-67
lines changed

8 files changed

+79
-67
lines changed

opendata.swiss/ui/app/components/ExternalLink.vue

Lines changed: 0 additions & 47 deletions
This file was deleted.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<template>
2+
<NuxtLink
3+
v-if="isExternal"
4+
:href="props.href"
5+
target="_blank"
6+
rel="noopener noreferrer"
7+
class="link--external">
8+
<slot />
9+
</NuxtLink>
10+
11+
<NuxtLinkLocale
12+
v-else
13+
:href="props.href"
14+
:target="props.target"
15+
:class="{ 'link--external': isExternal }"
16+
>
17+
<slot />
18+
</NuxtLinkLocale>
19+
20+
</template>
21+
22+
<script setup lang="ts">
23+
24+
import type { PropType } from 'vue'
25+
import isAbsolute from 'is-absolute-url';
26+
27+
const props = defineProps({
28+
href: {
29+
type: String,
30+
default: ''
31+
},
32+
target: {
33+
type: String as PropType<'_blank' | '_parent' | '_self' | '_top' | (string & object) | null | undefined>,
34+
default: undefined,
35+
required: false
36+
}
37+
})
38+
39+
const isExternal = computed(() => {
40+
if (!props.href) {
41+
return false
42+
}
43+
44+
if(props.href.startsWith('mailto')) {
45+
return false
46+
}
47+
48+
if(isAbsolute(props.href)) {
49+
const base = import.meta.client ? window.location : useRequestURL()
50+
51+
return new URL(props.href).host !== base.host;
52+
}
53+
54+
return false
55+
});
56+
</script>

opendata.swiss/ui/app/components/dataset-detail/OdsDatasetMetaInfo.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
v-if="props.dataset.getOdsAccrualPeriodicity"
3737
class="meta-info__item"
3838
>
39-
{{ t('message.dataset_detail.accrual_periodicity') }} <OdsExternalLink :href="props.dataset.getOdsAccrualPeriodicity.resource">{{ props.dataset.getOdsAccrualPeriodicity.label }}</OdsExternalLink>
39+
{{ t('message.dataset_detail.accrual_periodicity') }} <a class="link--external" :href="props.dataset.getOdsAccrualPeriodicity.resource">{{ props.dataset.getOdsAccrualPeriodicity.label }}</a>
4040
</span>
4141
</p>
4242
<p class="meta-info catalog-meta-info">
@@ -50,7 +50,6 @@ import { ref } from 'vue'
5050
import { useI18n } from 'vue-i18n'
5151
import type { Dataset } from '~/model/dataset'
5252
import OdsDatasetCatalogPanel from './OdsDatasetCatalogPanel.vue'
53-
import OdsExternalLink from '../ExternalLink.vue'
5453
5554
const { locale, t } = useI18n()
5655

opendata.swiss/ui/app/components/dataset-detail/OdsDetailsTable.vue

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<OdsInfoBlock :title="row.label">
55
<div v-if="row.type === 'value'">{{ row.value }}</div>
66
<div v-if="row.type === 'href'">
7-
<OdsExternalLink v-if="row.href && row.href.startsWith('http')" :href="row.href">{{ row.value }}</OdsExternalLink>
7+
<a v-if="row.href && row.href.startsWith('http')" :href="row.href" class="link--external">{{ row.value }}</a>
88
<a v-if="row.href && !row.href.startsWith('http')" :href="row.href">{{ row.value }}</a>
99
</div>
1010
</OdsInfoBlock>
@@ -17,11 +17,8 @@
1717
<script setup lang="ts">
1818
1919
import type { PropertyTableEntry, PropertyTableEntryNode } from '@piveau/sdk-vue';
20-
import OdsExternalLink from '@/components/ExternalLink.vue'
2120
import { computed } from 'vue'
2221
23-
24-
2522
interface TableEntry {
2623
id: string;
2724
label: string;

opendata.swiss/ui/nuxt.config.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import vuetify, {transformAssetUrls} from 'vite-plugin-vuetify'
1+
import vuetify, { transformAssetUrls } from 'vite-plugin-vuetify'
22

3-
import {resolve} from 'node:path'
3+
import { resolve } from 'node:path'
44

55
// https://nuxt.com/docs/api/configuration/nuxt-config
66
export default defineNuxtConfig({
77
compatibilityDate: '2025-07-15',
8-
devtools: {enabled: true},
8+
devtools: { enabled: true },
99
modules: [
1010
'@nuxt/eslint',
1111
'@nuxt/content',
@@ -14,7 +14,7 @@ export default defineNuxtConfig({
1414
'@nuxt/image',
1515
(_options, nuxt) => {
1616
nuxt.hooks.hook('vite:extendConfig', (config) => {
17-
config.plugins?.push(vuetify({autoImport: true}))
17+
config.plugins?.push(vuetify({ autoImport: true }))
1818
})
1919
},
2020
],
@@ -33,7 +33,7 @@ export default defineNuxtConfig({
3333
toc: {
3434
depth: 3,
3535
searchDepth: 3,
36-
}
36+
},
3737
}
3838
}
3939
},
@@ -44,7 +44,13 @@ export default defineNuxtConfig({
4444
'~/components/content',
4545
]
4646
},
47-
47+
mdc: {
48+
components: {
49+
map: {
50+
a: 'OdsProseA', // Map <a> tags to the OdsProseA component
51+
}
52+
}
53+
},
4854
build: {
4955
transpile: ['vuetify', 'form-data'],
5056
},
@@ -60,10 +66,10 @@ export default defineNuxtConfig({
6066
defaultLocale: 'de',
6167
strategy: 'prefix',
6268
locales: [
63-
{code: 'de', name: 'Deutsch', file: 'de.json'},
64-
{code: 'en', name: 'English', file: 'en.json'},
65-
{code: 'fr', name: 'Francais', file: 'fr.json'},
66-
{code: 'it', name: 'Itlaliano', file: 'it.json'},
69+
{ code: 'de', name: 'Deutsch', file: 'de.json' },
70+
{ code: 'en', name: 'English', file: 'en.json' },
71+
{ code: 'fr', name: 'Francais', file: 'fr.json' },
72+
{ code: 'it', name: 'Itlaliano', file: 'it.json' },
6773
]
6874
},
6975
nitro: {

opendata.swiss/ui/package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

opendata.swiss/ui/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"bootstrap": "^5.3.7",
2828
"decap-cms-app": "^3.8.3",
2929
"eslint": "^9.31.0",
30+
"is-absolute-url": "^4.0.1",
3031
"nuxt": "^4.0.0",
3132
"pinia": "^3.0.3",
3233
"react-bootstrap-typeahead": "^6.4.1",
@@ -46,9 +47,9 @@
4647
"@mdi/font": "^7.4.47",
4748
"@types/vue-select": "^3.16.8",
4849
"decap-server": "^3.3.0",
49-
"vite-plugin-vuetify": "^2.1.1",
5050
"vite-plugin-node-polyfills": "^0.24.0",
5151
"vite-plugin-static-copy": "^3.1.1",
52+
"vite-plugin-vuetify": "^2.1.1",
5253
"vuetify": "^3.9.2"
5354
}
54-
}
55+
}

opendata.swiss/ui/pages/datasets/[datasetId]/index.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ const breadcrumbs = computed(() => {
6565
<div class="hero__content">
6666
<OdsDatasetMetaInfo :dataset="resultEnhanced" />
6767
<h1 class="hero__title"> {{ resultEnhanced?.getTitle }} </h1>
68-
<h2 class="hero__subtitle"> {{ resultEnhanced?.getDescription }} </h2>
69-
<pre>{{ resultEnhanced?.getDescription }}</pre>
68+
<MDC :value="resultEnhanced?.getDescription ?? ''" />
7069
<!----><!---->
7170
<aside class="authors">
7271
<div class="disc-images" aria-hidden="true">

0 commit comments

Comments
 (0)