Skip to content

Commit

Permalink
feat(components): read more
Browse files Browse the repository at this point in the history
Signed-off-by: ZTL-UwU <[email protected]>
  • Loading branch information
ZTL-UwU committed May 26, 2024
1 parent 5c0785b commit 5cc4447
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 6 deletions.
7 changes: 4 additions & 3 deletions components/content/Alert.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@
const props = withDefaults(defineProps<{
title?: string;
icon?: string;
type?: 'info' | 'warning' | 'success' | 'danger';
type?: 'default' | 'info' | 'warning' | 'success' | 'danger';
to?: string;
target?: string;
}>(), {
type: 'info',
type: 'default',
});
const typeTwClass = {
info: '',
default: '',
info: 'border-sky-600 text-sky-600 [&>svg]:text-sky-600',
warning: 'border-amber-600 text-amber-600 [&>svg]:text-amber-600',
success: 'border-green-600 text-green-600 [&>svg]:text-green-600',
danger: 'border-red-600 text-red-600 [&>svg]:text-red-600',
Expand Down
27 changes: 27 additions & 0 deletions components/content/ReadMore.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<template>
<Alert :to="to" :target="target" icon="lucide:bookmark">
Read more in <span class="capitalize font-semibold">{{ computedTitle }}</span>
</Alert>
</template>

<script setup lang="ts">
const props = defineProps<{
title?: string;
to: string;
target?: string;
}>();
function createBreadcrumb(link: string = 'here') {
if (link.startsWith('http'))
return link.replace(/^https?:\/\//, '');
return link
.split('/')
.filter(Boolean)
.join(' > ')
.replace('Api', 'API');
}
// Guess title from link!
const computedTitle = computed<string>(() => props.title || createBreadcrumb(props.to));
</script>
26 changes: 24 additions & 2 deletions content/1.getting-started/3.writing/2.components.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ icon: 'lucide:component'
::code-group
::preview{filename="Preview"}
::alert{icon="lucide:info"}
An **info (default)** alert with `code` and a [link](/).
An **default** alert with `code` and a [link](/).
::

::alert{type="info" icon="lucide:info"}
An **info** alert with `code` and a [link](/).
::

::alert{type="success" icon="lucide:lightbulb"}
Expand All @@ -37,7 +41,11 @@ icon: 'lucide:component'

```md [Code]
::alert{icon="lucide:info"}
An **info (default)** alert with `code` and a [link](/).
An **default** alert with `code` and a [link](/).
::

::alert{type="info" icon="lucide:info"}
An **info** alert with `code` and a [link](/).
::

::alert{type="success" icon="lucide:lightbulb"}
Expand Down Expand Up @@ -66,6 +74,20 @@ icon: 'lucide:component'

`::callout` is an alias to `::alert`.

### Read More

::code-group
::preview{filename="Preview"}
:read-more{to="/getting-started/writing/markdown"}
:read-more{title="Nuxt website" to="https://nuxt.com/"}
::

```md [Code]
:read-more{to="/getting-started/writing/markdown"}
:read-more{title="Nuxt website" to="https://nuxt.com/"}
```
::

### Code Group

::code-group
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@
"shiki": "^1.6.0",
"vue-tsc": "^2.0.19"
}
}
}

0 comments on commit 5cc4447

Please sign in to comment.