Skip to content

Commit 736ac82

Browse files
committed
Функционал: AGWLinkBlock
1 parent f2174e6 commit 736ac82

5 files changed

Lines changed: 230 additions & 122 deletions

File tree

.vitepress/config/shared.ts

Lines changed: 105 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -6,126 +6,127 @@ import { tabsMarkdownPlugin } from 'vitepress-plugin-tabs'
66
import markdownItKdb from 'markdown-it-kbd'
77
import markdownItImplicitFigures from 'markdown-it-implicit-figures'
88

9+
/* Markdown */
10+
import linkBlock from '../theme/composables/linkBlock'
11+
912
import * as config from '../config.json'
1013

1114
/* GitLog */
1215
import UnoCSS from 'unocss/vite'
13-
import {
14-
GitChangelog,
15-
GitChangelogMarkdownSection
16-
} from '@nolebase/vitepress-plugin-git-changelog/vite'
16+
import { GitChangelog, GitChangelogMarkdownSection } from '@nolebase/vitepress-plugin-git-changelog/vite'
1717

1818
import { NolebaseGitChangelogOptions, YandexMetrikaOptions } from './plugins/index'
1919

2020
export const shared = defineConfig({
21-
srcDir: './docs',
22-
cleanUrls: true,
23-
head: [
24-
['link', { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }],
25-
['link', { rel: 'icon', type: 'image/png', href: '/favicon.png' }],
26-
['meta', { name: 'theme-color', content: config.head.themeColor }],
27-
['meta', { name: 'og:type', content: config.head.type }],
28-
['meta', { name: 'og:site_name', content: config.title }],
29-
['meta', { name: 'og:image', content: config.host + config.head.ogImage }],
30-
['meta', { name: 'twitter:card', content: 'summary_large_image' }],
31-
['meta', { name: 'twitter:image', content: config.host + config.head.ogImage }],
32-
['meta', { name: 'yandex-verification', content: YandexMetrikaOptions.webmaster.id }]
21+
srcDir: './docs',
22+
cleanUrls: true,
23+
head: [
24+
['link', { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }],
25+
['link', { rel: 'icon', type: 'image/png', href: '/favicon.png' }],
26+
['meta', { name: 'theme-color', content: config.head.themeColor }],
27+
['meta', { name: 'og:type', content: config.head.type }],
28+
['meta', { name: 'og:site_name', content: config.title }],
29+
['meta', { name: 'og:image', content: config.host + config.head.ogImage }],
30+
['meta', { name: 'twitter:card', content: 'summary_large_image' }],
31+
['meta', { name: 'twitter:image', content: config.host + config.head.ogImage }],
32+
['meta', { name: 'yandex-verification', content: YandexMetrikaOptions.webmaster.id }]
33+
],
34+
vite: {
35+
plugins: [
36+
UnoCSS(),
37+
GitChangelog(NolebaseGitChangelogOptions.plugin),
38+
GitChangelogMarkdownSection(NolebaseGitChangelogOptions.pluginSections)
3339
],
34-
vite: {
35-
plugins: [
36-
UnoCSS(),
37-
GitChangelog(NolebaseGitChangelogOptions.plugin),
38-
GitChangelogMarkdownSection(NolebaseGitChangelogOptions.pluginSections),
39-
],
40-
optimizeDeps: {
41-
exclude: ['@nolebase/vitepress-plugin-enhanced-readabilities/client']
42-
},
43-
ssr: {
44-
noExternal: [
45-
'@nolebase/vitepress-plugin-enhanced-readabilities',
46-
'@nolebase/vitepress-plugin-page-properties'
47-
]
48-
},
49-
resolve: {
50-
alias: {
51-
'@vitepress/theme': fileURLToPath(
52-
new URL('../node_modules/vitepress/dist/client/theme-default', import.meta.url)
53-
)
54-
}
55-
}
40+
optimizeDeps: {
41+
exclude: ['@nolebase/vitepress-plugin-enhanced-readabilities/client']
5642
},
57-
sitemap: {
58-
hostname: 'https://alt-kde.wiki'
43+
ssr: {
44+
noExternal: [
45+
'@nolebase/vitepress-plugin-enhanced-readabilities',
46+
'@nolebase/vitepress-plugin-page-properties'
47+
]
5948
},
60-
themeConfig: {
61-
logo: { src: '/logo.png', width: 36, height: 36, alt: "ALT KDE Wiki" },
62-
search: {
63-
provider: 'local',
64-
options: {
65-
locales: {
66-
root: {
67-
translations: {
68-
button: {
69-
buttonText: 'Поиск',
70-
buttonAriaLabel: 'Поиск'
71-
},
72-
modal: {
73-
noResultsText: 'Нет результатов по запросу',
74-
resetButtonTitle: 'Сбросить',
75-
footer: {
76-
selectText: 'для выбора',
77-
navigateText: 'для навигации',
78-
closeText: 'закрыть'
79-
}
80-
}
81-
}
82-
}
49+
resolve: {
50+
alias: {
51+
'@vitepress/theme': fileURLToPath(
52+
new URL('../node_modules/vitepress/dist/client/theme-default', import.meta.url)
53+
)
54+
}
55+
}
56+
},
57+
sitemap: {
58+
hostname: 'https://alt-kde.wiki'
59+
},
60+
themeConfig: {
61+
logo: { src: '/logo.png', width: 36, height: 36, alt: 'ALT KDE Wiki' },
62+
search: {
63+
provider: 'local',
64+
options: {
65+
locales: {
66+
root: {
67+
translations: {
68+
button: {
69+
buttonText: 'Поиск',
70+
buttonAriaLabel: 'Поиск'
71+
},
72+
modal: {
73+
noResultsText: 'Нет результатов по запросу',
74+
resetButtonTitle: 'Сбросить',
75+
footer: {
76+
selectText: 'для выбора',
77+
navigateText: 'для навигации',
78+
closeText: 'закрыть'
8379
}
80+
}
8481
}
85-
},
86-
socialLinks: [
87-
{
88-
icon: {
89-
svg: telegram
90-
},
91-
link: 'https://t.me/alt_kde'
92-
},
93-
{ icon: 'github', link: 'https://github.com/OlegShchavelev/ALTRegularKDEWiki' }
94-
],
95-
outline: {
96-
level: [2, 3],
97-
},
82+
}
83+
}
84+
}
9885
},
99-
markdown: {
100-
container: {
101-
tipLabel: 'Подсказка',
102-
warningLabel: 'Внимание',
103-
dangerLabel: 'Осторожно',
104-
infoLabel: 'Информация',
105-
detailsLabel: 'Подробнее',
86+
socialLinks: [
87+
{
88+
icon: {
89+
svg: telegram
10690
},
107-
config(md) {
108-
md.use(tabsMarkdownPlugin)
109-
md.use(markdownItKdb)
110-
md.use(markdownItImplicitFigures, {
111-
figcaption: 'title',
112-
copyAttrs: '^class$'
113-
})
114-
}
91+
link: 'https://t.me/alt_kde'
92+
},
93+
{ icon: 'github', link: 'https://github.com/OlegShchavelev/ALTRegularKDEWiki' }
94+
],
95+
outline: {
96+
level: [2, 3]
97+
}
98+
},
99+
markdown: {
100+
container: {
101+
tipLabel: 'Подсказка',
102+
warningLabel: 'Внимание',
103+
dangerLabel: 'Осторожно',
104+
infoLabel: 'Информация',
105+
detailsLabel: 'Подробнее'
115106
},
116-
transformPageData: (pageData) => {
117-
const canonicalUrl = `https://alt-kde.wiki/${pageData.relativePath}`
118-
.replace(/index\.md$/, '')
119-
.replace(/\.md$/, '.html')
107+
config(md) {
108+
md.use(tabsMarkdownPlugin)
109+
md.use(markdownItKdb)
110+
md.use(markdownItImplicitFigures, {
111+
figcaption: 'title',
112+
copyAttrs: '^class$'
113+
})
114+
md.use(linkBlock)
115+
}
116+
},
117+
transformPageData: (pageData) => {
118+
const canonicalUrl = `https://alt-kde.wiki/${pageData.relativePath}`
119+
.replace(/index\.md$/, '')
120+
.replace(/\.md$/, '.html')
120121

121-
pageData.frontmatter.head ??= []
122+
pageData.frontmatter.head ??= []
122123

123-
pageData.frontmatter.head.push(
124-
['link', { rel: 'canonical', href: canonicalUrl }],
125-
['meta', { name: 'og:title', content: pageData.title + config.head.titleSeponator + config.title }],
126-
)
127-
if (pageData.frontmatter.layout !== 'home') {
128-
pageData.description = `Cтатья написанная простым языком: «${pageData.title}» для ${config.title}. Последнее обновление ${config.title}: ${new Date(pageData.lastUpdated ?? new Date()).toLocaleString('ru-RU')}`
129-
}
124+
pageData.frontmatter.head.push(
125+
['link', { rel: 'canonical', href: canonicalUrl }],
126+
['meta', { name: 'og:title', content: pageData.title + config.head.titleSeponator + config.title }]
127+
)
128+
if (pageData.frontmatter.layout !== 'home') {
129+
pageData.description = `Cтатья написанная простым языком: «${pageData.title}» для ${config.title}. Последнее обновление ${config.title}: ${new Date(pageData.lastUpdated ?? new Date()).toLocaleString('ru-RU')}`
130130
}
131-
})
131+
}
132+
})
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<script setup lang="ts">
2+
import { homepage } from '../../../package.json'
3+
4+
const { href, title } = defineProps<{ href: string; title: string }>()
5+
6+
const isExternal = /https?:\/\//.test(href)
7+
</script>
8+
9+
<template>
10+
<ClientOnly>
11+
<a v-if="href" :href :target="isExternal ? '_blank' : undefined">
12+
<div class="custom-block link-block">
13+
<p class="custom-block-title">
14+
<slot />
15+
</p>
16+
<p>
17+
{{ title }}
18+
</p>
19+
<div class="footer">
20+
<div class="link">
21+
<img
22+
class="icon"
23+
:src="
24+
isExternal
25+
? `https://s2.googleusercontent.com/s2/favicons?domain_url=${href}&sz=96`
26+
: `/favicon.png`
27+
"
28+
/>
29+
<div class="domain">
30+
{{ decodeURI((isExternal ? '' : homepage.slice(0, -1)) + href) }}
31+
</div>
32+
</div>
33+
<div>
34+
{{ homepage.replace(/https?:/, '').replaceAll('/', '') }}
35+
</div>
36+
</div>
37+
</div>
38+
</a>
39+
</ClientOnly>
40+
</template>
41+
42+
<style scoped>
43+
.link-block {
44+
background-color: var(--vp-c-bg-soft);
45+
transition-duration: 0.25s;
46+
color: var(--vp-custom-block-info-text);
47+
}
48+
49+
.link-block:hover {
50+
border-color: var(--vp-c-brand);
51+
}
52+
53+
a,
54+
a:hover,
55+
a:active {
56+
text-decoration: none;
57+
}
58+
59+
.footer {
60+
margin: 8px 0;
61+
display: flex;
62+
justify-content: space-between;
63+
}
64+
65+
.link {
66+
max-width: 75%;
67+
display: flex;
68+
gap: 12px;
69+
align-items: center;
70+
}
71+
72+
@media (max-width: 960px) {
73+
.link {
74+
max-width: 50%;
75+
}
76+
}
77+
78+
.domain {
79+
overflow: hidden;
80+
white-space: nowrap;
81+
text-overflow: ellipsis;
82+
}
83+
84+
.icon {
85+
height: 24px;
86+
}
87+
</style>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export default function (md) {
2+
md.core.ruler.after('inline', 'link_block', (state) => {
3+
state.tokens.forEach((token, index, tokens) => {
4+
if (
5+
token.level === 1 &&
6+
token.type === 'inline' &&
7+
token.children.length > 2 &&
8+
token.children.at(0)?.type === 'link_open' &&
9+
token.children.at(-1)?.type === 'link_close'
10+
) {
11+
token.children[0].tag = 'AGWLinkBlock'
12+
token.children[token.children.length - 1].tag = 'AGWLinkBlock'
13+
}
14+
})
15+
})
16+
}

0 commit comments

Comments
 (0)