Skip to content

Commit

Permalink
feat(SEO): add vue-meta to manipulate html-header tags and attributes (
Browse files Browse the repository at this point in the history
…#10)

closes: #2
  • Loading branch information
devCrossNet authored Dec 30, 2017
1 parent 6f31bd9 commit 1d9b687
Show file tree
Hide file tree
Showing 17 changed files with 69 additions and 17 deletions.
21 changes: 17 additions & 4 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
"serve-favicon": "^2.4.5",
"vue": "^2.5.13",
"vue-i18n": "^7.3.3",
"vue-meta": "^1.4.0",
"vue-router": "^3.0.1",
"vue-server-renderer": "^2.5.13",
"vuex": "^3.0.1",
Expand Down
2 changes: 1 addition & 1 deletion src/app/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import VueButton from './shared/VueButton/VueButton.vue';
import VueGrid from './shared/VueGrid/VueGrid.vue';
import VueGridItem from './shared/VueGridItem/VueGridItem.vue';
import { loadLanguageAsync } from '../i18n';
import { loadLanguageAsync } from './plugins/i18n';
export default {
components: {
Expand Down
2 changes: 1 addition & 1 deletion src/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { sync } from 'vuex-router-sync';
import App from './App.vue';
import { store } from './store';
import { router } from './router';
import { i18n } from '../i18n';
import { i18n } from './plugins/i18n';
import { VueRouter } from 'vue-router/types/router';
import { Store } from 'vuex';

Expand Down
2 changes: 1 addition & 1 deletion src/app/components/Components/Components.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { mount, createLocalVue } from 'vue-test-utils';
import Vuex from 'vuex';
import { i18n } from '../../../i18n';
import { i18n } from '../../plugins/i18n';
import Components from './Components.vue';
import $style from 'identity-obj-proxy';

Expand Down
3 changes: 3 additions & 0 deletions src/app/components/Components/Components.vue
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@
import VueInput from '../../shared/VueInput/VueInput';
export default {
metaInfo: {
title: 'Components'
},
components: {
VueGrid,
VueGridItem,
Expand Down
2 changes: 1 addition & 1 deletion src/app/counter/Counter/Counter.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { mount, createLocalVue } from 'vue-test-utils';
import Vuex from 'vuex';
import { i18n } from '../../../i18n';
import { i18n } from '../../plugins/i18n';
import Counter from './Counter.vue';
import $style from 'identity-obj-proxy';

Expand Down
3 changes: 3 additions & 0 deletions src/app/counter/Counter/Counter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
import VueButton from '../../shared/VueButton/VueButton';
export default {
metaInfo: {
title: 'Counter'
},
components: {
VueGrid,
VueGridItem,
Expand Down
3 changes: 3 additions & 0 deletions src/app/home/Home/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import VueGridItem from '../../shared/VueGridItem/VueGridItem';
export default {
metaInfo: {
title: 'Home'
},
components: {
VueGrid,
VueGridItem,
Expand Down
8 changes: 7 additions & 1 deletion src/app/index.template.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<html data-vue-meta-server-rendered {{{ meta.inject().htmlAttrs.text() }}}>
<head>
{{{ meta.inject().meta.text() }}}
{{{ meta.inject().title.text() }}}
{{{ meta.inject().link.text() }}}
{{{ meta.inject().style.text() }}}
{{{ meta.inject().script.text() }}}
{{{ meta.inject().noscript.text() }}}
<meta charset="utf-8">
<title>vue-starter</title>
<meta name="mobile-web-app-capable" content="yes">
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/i18n.ts → src/app/plugins/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const i18n = new VueI18n({
locale: 'en',
fallbackLocale: 'en',
messages: {
en: require('../i18n/en.json'),
en: require('../../../i18n/en.json'),
},
});

Expand Down
2 changes: 2 additions & 0 deletions src/app/router.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import Vue from 'vue';
import VueRouter from 'vue-router';
import Meta from 'vue-meta';
import { homeRoutes } from './home/routes';
import { counterRoutes } from './counter/routes';
import { componentsRoutes } from './components/routes';

Vue.use(VueRouter);
Vue.use(Meta);

export const router = new VueRouter({
mode: 'history',
Expand Down
7 changes: 0 additions & 7 deletions src/async-component.d.ts

This file was deleted.

5 changes: 5 additions & 0 deletions src/custom-typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ declare module 'identity-obj-proxy' {
const $style: any;
export = $style;
}

declare module 'vue-meta' {
const meta: any;
export = meta;
}
3 changes: 3 additions & 0 deletions src/server/isomorphic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ export default (context: any) => {
const { app, router, store }: IApp = createApp();

router.push(context.url);

context.meta = app.$meta();

router
.onReady(() => {
const matchedComponents: Component[] = router.getMatchedComponents();
Expand Down
20 changes: 20 additions & 0 deletions src/vue.plugins.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* tslint:disable:no-shadowed-variable */

import Vue from 'vue';

declare module 'vue/types/vue' {
interface Vue {
$meta?: any;
}

interface VueConstructor {
prefetch?: (options: any) => {};
}
}

declare module 'vue/types/options' {
interface ComponentOptions<V extends Vue> {
metaInfo?: any;
prefetch?: any;
}
}

0 comments on commit 1d9b687

Please sign in to comment.