Skip to content

Commit

Permalink
Функционал: AGWLinkBlock
Browse files Browse the repository at this point in the history
  • Loading branch information
X1Z53 committed Aug 8, 2024
1 parent f2174e6 commit 736ac82
Show file tree
Hide file tree
Showing 5 changed files with 230 additions and 122 deletions.
209 changes: 105 additions & 104 deletions .vitepress/config/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,126 +6,127 @@ import { tabsMarkdownPlugin } from 'vitepress-plugin-tabs'
import markdownItKdb from 'markdown-it-kbd'
import markdownItImplicitFigures from 'markdown-it-implicit-figures'

/* Markdown */
import linkBlock from '../theme/composables/linkBlock'

import * as config from '../config.json'

/* GitLog */
import UnoCSS from 'unocss/vite'
import {
GitChangelog,
GitChangelogMarkdownSection
} from '@nolebase/vitepress-plugin-git-changelog/vite'
import { GitChangelog, GitChangelogMarkdownSection } from '@nolebase/vitepress-plugin-git-changelog/vite'

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

export const shared = defineConfig({
srcDir: './docs',
cleanUrls: true,
head: [
['link', { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }],
['link', { rel: 'icon', type: 'image/png', href: '/favicon.png' }],
['meta', { name: 'theme-color', content: config.head.themeColor }],
['meta', { name: 'og:type', content: config.head.type }],
['meta', { name: 'og:site_name', content: config.title }],
['meta', { name: 'og:image', content: config.host + config.head.ogImage }],
['meta', { name: 'twitter:card', content: 'summary_large_image' }],
['meta', { name: 'twitter:image', content: config.host + config.head.ogImage }],
['meta', { name: 'yandex-verification', content: YandexMetrikaOptions.webmaster.id }]
srcDir: './docs',
cleanUrls: true,
head: [
['link', { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }],
['link', { rel: 'icon', type: 'image/png', href: '/favicon.png' }],
['meta', { name: 'theme-color', content: config.head.themeColor }],
['meta', { name: 'og:type', content: config.head.type }],
['meta', { name: 'og:site_name', content: config.title }],
['meta', { name: 'og:image', content: config.host + config.head.ogImage }],
['meta', { name: 'twitter:card', content: 'summary_large_image' }],
['meta', { name: 'twitter:image', content: config.host + config.head.ogImage }],
['meta', { name: 'yandex-verification', content: YandexMetrikaOptions.webmaster.id }]
],
vite: {
plugins: [
UnoCSS(),
GitChangelog(NolebaseGitChangelogOptions.plugin),
GitChangelogMarkdownSection(NolebaseGitChangelogOptions.pluginSections)
],
vite: {
plugins: [
UnoCSS(),
GitChangelog(NolebaseGitChangelogOptions.plugin),
GitChangelogMarkdownSection(NolebaseGitChangelogOptions.pluginSections),
],
optimizeDeps: {
exclude: ['@nolebase/vitepress-plugin-enhanced-readabilities/client']
},
ssr: {
noExternal: [
'@nolebase/vitepress-plugin-enhanced-readabilities',
'@nolebase/vitepress-plugin-page-properties'
]
},
resolve: {
alias: {
'@vitepress/theme': fileURLToPath(
new URL('../node_modules/vitepress/dist/client/theme-default', import.meta.url)
)
}
}
optimizeDeps: {
exclude: ['@nolebase/vitepress-plugin-enhanced-readabilities/client']
},
sitemap: {
hostname: 'https://alt-kde.wiki'
ssr: {
noExternal: [
'@nolebase/vitepress-plugin-enhanced-readabilities',
'@nolebase/vitepress-plugin-page-properties'
]
},
themeConfig: {
logo: { src: '/logo.png', width: 36, height: 36, alt: "ALT KDE Wiki" },
search: {
provider: 'local',
options: {
locales: {
root: {
translations: {
button: {
buttonText: 'Поиск',
buttonAriaLabel: 'Поиск'
},
modal: {
noResultsText: 'Нет результатов по запросу',
resetButtonTitle: 'Сбросить',
footer: {
selectText: 'для выбора',
navigateText: 'для навигации',
closeText: 'закрыть'
}
}
}
}
resolve: {
alias: {
'@vitepress/theme': fileURLToPath(
new URL('../node_modules/vitepress/dist/client/theme-default', import.meta.url)
)
}
}
},
sitemap: {
hostname: 'https://alt-kde.wiki'
},
themeConfig: {
logo: { src: '/logo.png', width: 36, height: 36, alt: 'ALT KDE Wiki' },
search: {
provider: 'local',
options: {
locales: {
root: {
translations: {
button: {
buttonText: 'Поиск',
buttonAriaLabel: 'Поиск'
},
modal: {
noResultsText: 'Нет результатов по запросу',
resetButtonTitle: 'Сбросить',
footer: {
selectText: 'для выбора',
navigateText: 'для навигации',
closeText: 'закрыть'
}
}
}
},
socialLinks: [
{
icon: {
svg: telegram
},
link: 'https://t.me/alt_kde'
},
{ icon: 'github', link: 'https://github.com/OlegShchavelev/ALTRegularKDEWiki' }
],
outline: {
level: [2, 3],
},
}
}
}
},
markdown: {
container: {
tipLabel: 'Подсказка',
warningLabel: 'Внимание',
dangerLabel: 'Осторожно',
infoLabel: 'Информация',
detailsLabel: 'Подробнее',
socialLinks: [
{
icon: {
svg: telegram
},
config(md) {
md.use(tabsMarkdownPlugin)
md.use(markdownItKdb)
md.use(markdownItImplicitFigures, {
figcaption: 'title',
copyAttrs: '^class$'
})
}
link: 'https://t.me/alt_kde'
},
{ icon: 'github', link: 'https://github.com/OlegShchavelev/ALTRegularKDEWiki' }
],
outline: {
level: [2, 3]
}
},
markdown: {
container: {
tipLabel: 'Подсказка',
warningLabel: 'Внимание',
dangerLabel: 'Осторожно',
infoLabel: 'Информация',
detailsLabel: 'Подробнее'
},
transformPageData: (pageData) => {
const canonicalUrl = `https://alt-kde.wiki/${pageData.relativePath}`
.replace(/index\.md$/, '')
.replace(/\.md$/, '.html')
config(md) {
md.use(tabsMarkdownPlugin)
md.use(markdownItKdb)
md.use(markdownItImplicitFigures, {
figcaption: 'title',
copyAttrs: '^class$'
})
md.use(linkBlock)
}
},
transformPageData: (pageData) => {
const canonicalUrl = `https://alt-kde.wiki/${pageData.relativePath}`
.replace(/index\.md$/, '')
.replace(/\.md$/, '.html')

pageData.frontmatter.head ??= []
pageData.frontmatter.head ??= []

pageData.frontmatter.head.push(
['link', { rel: 'canonical', href: canonicalUrl }],
['meta', { name: 'og:title', content: pageData.title + config.head.titleSeponator + config.title }],
)
if (pageData.frontmatter.layout !== 'home') {
pageData.description = `Cтатья написанная простым языком: «${pageData.title}» для ${config.title}. Последнее обновление ${config.title}: ${new Date(pageData.lastUpdated ?? new Date()).toLocaleString('ru-RU')}`
}
pageData.frontmatter.head.push(
['link', { rel: 'canonical', href: canonicalUrl }],
['meta', { name: 'og:title', content: pageData.title + config.head.titleSeponator + config.title }]
)
if (pageData.frontmatter.layout !== 'home') {
pageData.description = `Cтатья написанная простым языком: «${pageData.title}» для ${config.title}. Последнее обновление ${config.title}: ${new Date(pageData.lastUpdated ?? new Date()).toLocaleString('ru-RU')}`
}
})
}
})
87 changes: 87 additions & 0 deletions .vitepress/theme/components/AGWLinkBlock.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<script setup lang="ts">
import { homepage } from '../../../package.json'
const { href, title } = defineProps<{ href: string; title: string }>()
const isExternal = /https?:\/\//.test(href)
</script>

<template>
<ClientOnly>
<a v-if="href" :href :target="isExternal ? '_blank' : undefined">
<div class="custom-block link-block">
<p class="custom-block-title">
<slot />
</p>
<p>
{{ title }}
</p>
<div class="footer">
<div class="link">
<img
class="icon"
:src="
isExternal
? `https://s2.googleusercontent.com/s2/favicons?domain_url=${href}&sz=96`
: `/favicon.png`
"
/>
<div class="domain">
{{ decodeURI((isExternal ? '' : homepage.slice(0, -1)) + href) }}
</div>
</div>
<div>
{{ homepage.replace(/https?:/, '').replaceAll('/', '') }}
</div>
</div>
</div>
</a>
</ClientOnly>
</template>

<style scoped>
.link-block {
background-color: var(--vp-c-bg-soft);
transition-duration: 0.25s;
color: var(--vp-custom-block-info-text);
}
.link-block:hover {
border-color: var(--vp-c-brand);
}
a,
a:hover,
a:active {
text-decoration: none;
}
.footer {
margin: 8px 0;
display: flex;
justify-content: space-between;
}
.link {
max-width: 75%;
display: flex;
gap: 12px;
align-items: center;
}
@media (max-width: 960px) {
.link {
max-width: 50%;
}
}
.domain {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.icon {
height: 24px;
}
</style>
16 changes: 16 additions & 0 deletions .vitepress/theme/composables/linkBlock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export default function (md) {
md.core.ruler.after('inline', 'link_block', (state) => {
state.tokens.forEach((token, index, tokens) => {
if (
token.level === 1 &&
token.type === 'inline' &&
token.children.length > 2 &&
token.children.at(0)?.type === 'link_open' &&
token.children.at(-1)?.type === 'link_close'
) {
token.children[0].tag = 'AGWLinkBlock'
token.children[token.children.length - 1].tag = 'AGWLinkBlock'
}
})
})
}
Loading

0 comments on commit 736ac82

Please sign in to comment.