mirror of
https://github.com/eugene-serb/wavelovers.git
synced 2023-09-09 23:41:16 +03:00
- recoded MetaTagUpdater.
- added metas array with metas. - added interfaces IRouteMeta, IMeta, ITag. - deleted metas from routes. - modified metas by types. - updated router index. - up minor version.
This commit is contained in:
parent
6b94c95602
commit
b368b359d8
@ -15,4 +15,4 @@
|
||||
webvisor: true
|
||||
});</script><style>[v-cloak] {
|
||||
display: none;
|
||||
}</style><script defer="defer" src="/js/chunk-vendors.34a275bd.js"></script><script defer="defer" src="/js/app.c1a049b3.js"></script><link href="/css/app.61999447.css" rel="stylesheet"></head><body><div id="app" class="app" v-cloak></div><noscript>You need to enable JavaScript to run this app.</noscript><noscript><div><img src="https://mc.yandex.ru/watch/89252711" style="position:absolute; left:-9999px;" alt=""/></div></noscript></body></html>
|
||||
}</style><script defer="defer" src="/js/chunk-vendors.34a275bd.js"></script><script defer="defer" src="/js/app.5845d133.js"></script><link href="/css/app.61999447.css" rel="stylesheet"></head><body><div id="app" class="app" v-cloak></div><noscript>You need to enable JavaScript to run this app.</noscript><noscript><div><img src="https://mc.yandex.ru/watch/89252711" style="position:absolute; left:-9999px;" alt=""/></div></noscript></body></html>
|
2
docs/js/app.5845d133.js
Normal file
2
docs/js/app.5845d133.js
Normal file
File diff suppressed because one or more lines are too long
1
docs/js/app.5845d133.js.map
Normal file
1
docs/js/app.5845d133.js.map
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "wavelovers",
|
||||
"version": "1.0.19",
|
||||
"version": "1.1.0",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "wavelovers",
|
||||
"version": "1.0.19",
|
||||
"version": "1.1.0",
|
||||
"license": "GNU GPL v3",
|
||||
"dependencies": {
|
||||
"core-js": "^3.8.3",
|
||||
|
@ -2,7 +2,7 @@
|
||||
"name": "wavelovers",
|
||||
"description": "Wavelovers. Use your device vibration correctly. Make a massager out of a gamepad.",
|
||||
"keywords": [ "wavelovers", "gamepad-vibrator", "gamepad-test-tool", "gamepad-vibration-test-tool" ],
|
||||
"version": "1.0.19",
|
||||
"version": "1.1.0",
|
||||
"license": "GNU GPL v3",
|
||||
"homepage": "https://wavelovers.ru/",
|
||||
"author": {
|
||||
@ -46,4 +46,3 @@
|
||||
"typescript": "~4.5.5"
|
||||
}
|
||||
}
|
||||
|
||||
|
46
src/router/assets/metas.ts
Normal file
46
src/router/assets/metas.ts
Normal file
@ -0,0 +1,46 @@
|
||||
import IRouteMeta from '@/router/models/IRouteMeta';
|
||||
import metaPatterns from '@/router/assets/metas/Patterns';
|
||||
import metaCustom from '@/router/assets/metas/Custom';
|
||||
import metaManual from '@/router/assets/metas/Manual';
|
||||
import metaDiagnostic from '@/router/assets/metas/Diagnostic';
|
||||
import metaFaq from '@/router/assets/metas/Faq';
|
||||
import metaAbout from '@/router/assets/metas/About';
|
||||
import metaDonate from '@/router/assets/metas/Donate';
|
||||
import meta404 from '@/router/assets/metas/404';
|
||||
|
||||
const metas: Array<IRouteMeta> = [
|
||||
{
|
||||
route: '/',
|
||||
meta: metaPatterns,
|
||||
},
|
||||
{
|
||||
route: '/custom',
|
||||
meta: metaCustom,
|
||||
},
|
||||
{
|
||||
route: '/manual',
|
||||
meta: metaManual,
|
||||
},
|
||||
{
|
||||
route: '/diagnostic',
|
||||
meta: metaDiagnostic,
|
||||
},
|
||||
{
|
||||
route: '/faq',
|
||||
meta: metaFaq,
|
||||
},
|
||||
{
|
||||
route: '/about',
|
||||
meta: metaAbout,
|
||||
},
|
||||
{
|
||||
route: '/donate',
|
||||
meta: metaDonate,
|
||||
},
|
||||
{
|
||||
route: '/404',
|
||||
meta: meta404,
|
||||
},
|
||||
];
|
||||
|
||||
export default metas;
|
@ -1,4 +1,6 @@
|
||||
const meta = {
|
||||
import IMeta from '@/router/models/IMeta';
|
||||
|
||||
const meta: IMeta = {
|
||||
title: 'Wavelovers – Page not found',
|
||||
metaTags: [
|
||||
{
|
||||
|
@ -1,4 +1,6 @@
|
||||
const meta = {
|
||||
import IMeta from '@/router/models/IMeta';
|
||||
|
||||
const meta: IMeta = {
|
||||
title: 'Wavelovers – About',
|
||||
metaTags: [
|
||||
{
|
||||
|
@ -1,4 +1,6 @@
|
||||
const meta = {
|
||||
import IMeta from '@/router/models/IMeta';
|
||||
|
||||
const meta: IMeta = {
|
||||
title: 'Wavelovers – Custom',
|
||||
metaTags: [
|
||||
{
|
||||
|
@ -1,4 +1,6 @@
|
||||
const meta = {
|
||||
import IMeta from '@/router/models/IMeta';
|
||||
|
||||
const meta: IMeta = {
|
||||
title: 'Wavelovers – Diagnostic',
|
||||
metaTags: [
|
||||
{
|
||||
|
@ -1,4 +1,6 @@
|
||||
const meta = {
|
||||
import IMeta from '@/router/models/IMeta';
|
||||
|
||||
const meta: IMeta = {
|
||||
title: 'Wavelovers – Donate',
|
||||
metaTags: [
|
||||
{
|
||||
|
@ -1,4 +1,6 @@
|
||||
const meta = {
|
||||
import IMeta from '@/router/models/IMeta';
|
||||
|
||||
const meta: IMeta = {
|
||||
title: 'Wavelovers – FAQ',
|
||||
metaTags: [
|
||||
{
|
||||
|
@ -1,4 +1,6 @@
|
||||
const meta = {
|
||||
import IMeta from '@/router/models/IMeta';
|
||||
|
||||
const meta: IMeta = {
|
||||
title: 'Wavelovers – Manual',
|
||||
metaTags: [
|
||||
{
|
||||
|
@ -1,4 +1,6 @@
|
||||
const meta = {
|
||||
import IMeta from '@/router/models/IMeta';
|
||||
|
||||
const meta: IMeta = {
|
||||
title: 'Wavelovers',
|
||||
metaTags: [
|
||||
{
|
||||
|
@ -1,61 +1,45 @@
|
||||
import { RouteRecordRaw } from 'vue-router';
|
||||
import metaPatterns from '@/router/assets/metas/Patterns';
|
||||
import metaCustom from '@/router/assets/metas/Custom';
|
||||
import metaManual from '@/router/assets/metas/Manual';
|
||||
import metaDiagnostic from '@/router/assets/metas/Diagnostic';
|
||||
import metaFaq from '@/router/assets/metas/Faq';
|
||||
import metaAbout from '@/router/assets/metas/About';
|
||||
import metaDonate from '@/router/assets/metas/Donate';
|
||||
import meta404 from '@/router/assets/metas/404';
|
||||
|
||||
const routes: Array<RouteRecordRaw> = [
|
||||
{
|
||||
path: '/',
|
||||
name: 'patterns-view',
|
||||
component: () => import('@/views/PatternsView.vue'),
|
||||
meta: metaPatterns,
|
||||
},
|
||||
{
|
||||
path: '/custom',
|
||||
name: 'custom-view',
|
||||
component: () => import('@/views/CustomView.vue'),
|
||||
meta: metaCustom,
|
||||
},
|
||||
{
|
||||
path: '/manual',
|
||||
name: 'manual-view',
|
||||
component: () => import('@/views/ManualView.vue'),
|
||||
meta: metaManual,
|
||||
},
|
||||
{
|
||||
path: '/diagnostic',
|
||||
name: 'diagnostic-view',
|
||||
component: () => import('@/views/DiagnosticView.vue'),
|
||||
meta: metaDiagnostic,
|
||||
},
|
||||
{
|
||||
path: '/faq',
|
||||
name: 'faq-view',
|
||||
component: () => import('@/views/FaqView.vue'),
|
||||
meta: metaFaq,
|
||||
},
|
||||
{
|
||||
path: '/about',
|
||||
name: 'about-view',
|
||||
component: () => import('@/views/AboutView.vue'),
|
||||
meta: metaAbout,
|
||||
},
|
||||
{
|
||||
path: '/donate',
|
||||
name: 'donate-view',
|
||||
component: () => import('@/views/DonateView.vue'),
|
||||
meta: metaDonate,
|
||||
},
|
||||
{
|
||||
path: '/404',
|
||||
name: '404',
|
||||
component: () => import('@/views/NotFoundView.vue'),
|
||||
meta: meta404,
|
||||
},
|
||||
{
|
||||
path: '/:catchAll(.*)*',
|
||||
|
@ -6,6 +6,7 @@ import QueryRouter from '@/router/modules/QueryRouter';
|
||||
import MetaTagUpdater from '@/router/modules/MetaTagUpdater';
|
||||
import routes from '@/router/assets/routes';
|
||||
import queries from '@/router/assets/queries';
|
||||
import metas from '@/router/assets/metas';
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(process.env.BASE_URL),
|
||||
@ -18,7 +19,7 @@ router.beforeEach((
|
||||
next: NavigationGuardNext
|
||||
) => {
|
||||
QueryRouter.update(to, from, next, router, queries);
|
||||
MetaTagUpdater.update(to, from, next)
|
||||
MetaTagUpdater.update(to, from, next, metas)
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
9
src/router/models/IMeta.ts
Normal file
9
src/router/models/IMeta.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import ITag from '@/router/models/ITag';
|
||||
|
||||
interface IMeta {
|
||||
title: string;
|
||||
metaTags: Array<ITag>;
|
||||
linkTags: Array<ITag>;
|
||||
}
|
||||
|
||||
export default IMeta;
|
8
src/router/models/IRouteMeta.ts
Normal file
8
src/router/models/IRouteMeta.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import IMeta from '@/router/models/IMeta';
|
||||
|
||||
interface IRouteMeta {
|
||||
route: string;
|
||||
meta: IMeta;
|
||||
}
|
||||
|
||||
export default IRouteMeta;
|
5
src/router/models/ITag.ts
Normal file
5
src/router/models/ITag.ts
Normal file
@ -0,0 +1,5 @@
|
||||
interface ITag {
|
||||
[key: string]: string;
|
||||
}
|
||||
|
||||
export default ITag;
|
@ -1,6 +1,6 @@
|
||||
import {
|
||||
NavigationGuardNext, RouteLocationNormalized, RouteRecordNormalized
|
||||
} from "vue-router";
|
||||
import { NavigationGuardNext, RouteLocationNormalized } from "vue-router";
|
||||
import IRouteMeta from "@/router/models/IRouteMeta";
|
||||
import ITag from '@/router/models/ITag';
|
||||
|
||||
function appendTags(tagsArray: object[], type: string) {
|
||||
tagsArray.map(
|
||||
@ -21,7 +21,8 @@ function appendTags(tagsArray: object[], type: string) {
|
||||
function updateMetatag(
|
||||
to: RouteLocationNormalized,
|
||||
from: RouteLocationNormalized,
|
||||
next: NavigationGuardNext
|
||||
next: NavigationGuardNext,
|
||||
metas: Array<IRouteMeta>
|
||||
) {
|
||||
Array.from(document.querySelectorAll('[data-vue-router-controlled]'))
|
||||
.map(el => {
|
||||
@ -30,27 +31,23 @@ function updateMetatag(
|
||||
}
|
||||
});
|
||||
|
||||
const hasTitle: RouteRecordNormalized =
|
||||
to.matched.slice().reverse()
|
||||
.find(r => r.meta && r.meta.title) as RouteRecordNormalized;
|
||||
const hasMetas: RouteRecordNormalized =
|
||||
to.matched.slice().reverse()
|
||||
.find(r => r.meta && r.meta.metaTags) as RouteRecordNormalized;
|
||||
const hasLinks: RouteRecordNormalized =
|
||||
to.matched.slice().reverse()
|
||||
.find(r => r.meta && r.meta.linkTags) as RouteRecordNormalized;
|
||||
let title: string = '' as string;
|
||||
let metaTags: Array<ITag> = [] as Array<ITag>;
|
||||
let linkTags: Array<ITag> = [] as Array<ITag>;
|
||||
|
||||
if (hasTitle) {
|
||||
document.title = hasTitle.meta.title as string;
|
||||
metas.forEach((item) => {
|
||||
if (item.route === to.fullPath) {
|
||||
if (item.meta) {
|
||||
title = item.meta.title;
|
||||
metaTags = item.meta.metaTags;
|
||||
linkTags = item.meta.linkTags;
|
||||
}
|
||||
if (hasMetas) {
|
||||
const metaTags: object[] = hasMetas.meta.metaTags as object[];
|
||||
appendTags(metaTags, 'meta');
|
||||
}
|
||||
if (hasLinks) {
|
||||
const linkTags: object[] = hasLinks.meta.linkTags as object[];
|
||||
appendTags(linkTags, 'link');
|
||||
}
|
||||
});
|
||||
|
||||
if (title) document.title = title;
|
||||
if (metaTags) appendTags(metaTags, 'meta');
|
||||
if (linkTags) appendTags(linkTags, 'link');
|
||||
|
||||
return next();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user