Skip to content

Commit

Permalink
feat: linkify game description
Browse files Browse the repository at this point in the history
  • Loading branch information
eyemono-moe committed Aug 24, 2024
1 parent 9abc107 commit 158d09e
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 4 deletions.
2 changes: 1 addition & 1 deletion components/content/ProseA.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<NuxtLink
:href="href"
:target="target"
class="text-text-link underline visited:text-text-visited hover:no-underline"
class="link"
>
<slot />
</NuxtLink>
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,15 @@
"@vee-validate/valibot": "^4.13.2",
"@vuepic/vue-datepicker": "^9.0.1",
"date-fns": "^3.3.1",
"linkify-html": "^4.1.3",
"linkifyjs": "^4.1.3",
"radix-vue": "^1.2.2",
"sass": "^1.70.0",
"valibot": "^0.33.3",
"vee-validate": "^4.12.4",
"vue-advanced-cropper": "^2.8.8",
"vue-toast-notification": "^3"
"vue-toast-notification": "^3",
"xss": "^1.0.15"
},
"peerDependencies": {
"eslint": ">=9.0.0"
Expand Down
7 changes: 6 additions & 1 deletion pages/entry/[gameId]/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,12 @@ const loadFallbackImage = (e: Event) => {
{{ game.place }}
</div>
</div>
<ProseP>{{ game.description }}</ProseP>
<p
v-linkify
class="my-4 whitespace-pre-wrap break-keep break-anywhere body"
>
{{ game.description }}
</p>
<div
v-if="canEdit"
class="w-full flex justify-center"
Expand Down
24 changes: 24 additions & 0 deletions plugins/00.linkify.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import linkifyHtml from 'linkify-html'
import type { Opts } from 'linkifyjs'
import xss from 'xss'

const linkify = (raw: string, options?: Opts) => {
const defaultOptions: Opts = {
className: 'link',
}
options = { ...defaultOptions, ...options }

const safeHtml = xss(raw)
return linkifyHtml(safeHtml, options)
}

export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.vueApp.directive<HTMLElement, Opts>('linkify', {
beforeMount(el, binding) {
el.innerHTML = linkify(el.innerHTML, binding.value)
},
updated(el, binding) {
el.innerHTML = linkify(el.innerHTML, binding.value)
},
})
})
35 changes: 34 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions unocss.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ export default defineConfig({
'body': 'text-body-m md:text-body-l',
'label': 'text-label-m md:text-label-l',
'caption': 'text-caption-l md:text-caption-m',
'link': 'text-text-link underline visited:text-text-visited hover:no-underline break-anywhere',
},
rules: [
[
Expand Down

0 comments on commit 158d09e

Please sign in to comment.