Skip to content

Commit

Permalink
JSON-LD data in data/json-ld
Browse files Browse the repository at this point in the history
  • Loading branch information
MattIPv4 committed Apr 5, 2020
1 parent e4a45bf commit 6f08bf3
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 86 deletions.
7 changes: 0 additions & 7 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ module.exports = {
indent: 0,
},
},
{
files: ['components/json-ld/*.vue'],
rules: {
'vue/html-indent': 0,
},
},
],
rules: {
indent: ['error', 4],
Expand All @@ -48,6 +42,5 @@ module.exports = {
}],
'vue/no-unused-vars': 0,
'vue/html-self-closing': 0,
'vue/require-component-is': 0,
},
};
37 changes: 6 additions & 31 deletions components/json-ld/tutorial.vue
Original file line number Diff line number Diff line change
@@ -1,38 +1,10 @@
<template>
<Script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "TechArticle",
"name": "{{ tutorial.name }}",
"headline": "{{ tutorial.name }}",
"description": "{{ tutorial.description }}",
"keywords": "{{ tutorial.keywords && tutorial.keywords.join(',') }}",
"url": "{{ base() }}{{ library }}/tutorials/{{ tutorialName }}",
"inLanguage": "en",
"accessMode": "textual",
"accessModeSufficient": "textual",
"isAccessibleForFree": true,
"isPartOf": "{{ base() }}{{ library }}/tutorials",
"author": {
"@type": "Person",
"name": "{{ tutorial.author.name }}"
},
"publisher": {
"@type": "Organization",
"name": "cdnjs",
"url": "{{ base() }}"
},
"sourceOrganization": {
"@type": "Organization",
"name": "cdnjs",
"url": "{{ base() }}"
}
}
</Script>
<Script v-html="json" type="application/ld+json"></Script>
</template>

<script>
import Script from '../script';
import Tutorial from '../../data/json-ld/tutorial';
export default {
name: 'JSONLDTutorial',
Expand All @@ -44,7 +16,10 @@
tutorial: Object,
tutorialName: String,
},
methods: {
computed: {
json () {
return Tutorial(this.base, this.$props.tutorial, this.$props.tutorialName, this.$props.library);
},
base () {
const origin = process.env.SITE_HOST ||
(typeof (window) !== 'undefined' ? window.location.origin : '/');
Expand Down
39 changes: 11 additions & 28 deletions components/json-ld/tutorials.vue
Original file line number Diff line number Diff line change
@@ -1,34 +1,10 @@
<template>
<Script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "CreativeWorkSeries",
"name": "{{ library }} Tutorials",
"headline": "{{ library }} Tutorials",
"description": "Tutorials for {{ library }} on cdnjs",
"keywords": "{{ keywords() }}",
"url": "{{ base() }}{{ library }}/tutorials",
"inLanguage": "en",
"accessMode": "textual",
"accessModeSufficient": "textual",
"isAccessibleForFree": true,
"isPartOf": "{{ base() }}{{ library }}",
"publisher": {
"@type": "Organization",
"name": "cdnjs",
"url": "{{ base() }}"
},
"sourceOrganization": {
"@type": "Organization",
"name": "cdnjs",
"url": "{{ base() }}"
}
}
</Script>
<Script v-html="json" type="application/ld+json"></Script>
</template>

<script>
import Script from '../script';
import Tutorials from '../../data/json-ld/tutorials';
export default {
name: 'JSONLDTutorials',
Expand All @@ -39,10 +15,17 @@
library: String,
tutorials: Object,
},
methods: {
computed: {
json () {
return Tutorials(this.base, this.$props.library, this.$props.tutorials, this.keywords);
},
keywords () {
const tags = [];
for (const tutorial of Object.values(this.$props.tutorials)) { if (tutorial.keywords) { tags.push(...tutorial.keywords); } }
for (const tutorial of Object.values(this.$props.tutorials)) {
if (tutorial.keywords) {
tags.push(...tutorial.keywords);
}
}
return tags.join(',');
},
base () {
Expand Down
25 changes: 6 additions & 19 deletions components/json-ld/website.vue
Original file line number Diff line number Diff line change
@@ -1,33 +1,20 @@
<template>
<Script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "WebSite",
"name": "cdnjs",
"alternateName": "CDNJS",
"description": "The #1 free and open source CDN built to make life easier for developers",
"logo": "{{ base() }}favicon.png",
"thumbnailUrl": "{{ base() }}banner.png",
"url": "{{ base() }}",
"sameAs": ["https://github.com/cdnjs", "https://twitter.com/cdnjs", "https://linkedin.com/company/cdnjs"],
"potentialAction": {
"@type": "SearchAction",
"target": "{{ base() }}libraries?&q={query}",
"query": "required"
}
}
</Script>
<Script v-html="json" type="application/ld+json"></Script>
</template>

<script>
import Script from '../script';
import WebSite from '../../data/json-ld/website';
export default {
name: 'JSONLDWebSite',
components: {
Script,
},
methods: {
computed: {
json () {
return WebSite(this.base);
},
base () {
const origin = process.env.SITE_HOST ||
(typeof (window) !== 'undefined' ? window.location.origin : '/');
Expand Down
1 change: 1 addition & 0 deletions components/script.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<template>
<!-- eslint-disable-next-line vue/require-component-is -->
<component is="script" v-html="content"></component>
</template>

Expand Down
2 changes: 1 addition & 1 deletion components/tutorial_list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

<script>
import utm from '../util/utm';
import JSONLDTutorials from '../../../../components/json-ld/tutorials';
import JSONLDTutorials from './json-ld/tutorials';
export default {
name: 'TutorialList',
Expand Down
31 changes: 31 additions & 0 deletions data/json-ld/tutorial.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export default (base, tutorial, tutorialName, library) => JSON.stringify({
'@context': 'http://schema.org',
'@type': 'TechArticle',
name: tutorial.name,
headline: tutorial.name,
description: tutorial.description,
keywords: tutorial.keywords && tutorial.keywords.join(','),
url: `${base}libraries/${library}/tutorials/${tutorialName}`,
inLanguage: 'en',
accessMode: 'textual',
accessModeSufficient: 'textual',
isAccessibleForFree: true,
isPartOf: {
'@type': 'CreativeWorkSeries',
url: `${base}libraries/${library}/tutorials`,
},
author: {
'@type': 'Person',
name: '{{ tutorial.author.name }}',
},
publisher: {
'@type': 'Organization',
name: 'cdnjs',
url: '{{ base() }}',
},
sourceOrganization: {
'@type': 'Organization',
name: 'cdnjs',
url: '{{ base() }}',
},
});
29 changes: 29 additions & 0 deletions data/json-ld/tutorials.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export default (base, library, tutorials, keywords) => JSON.stringify({
'@context': 'http://schema.org',
'@type': 'CreativeWorkSeries',
name: `${library} Tutorials`,
headline: `${library} Tutorials`,
description: `Tutorials for ${library} on cdnjs`,
keywords,
url: `${base}libraries/${library}/tutorials`,
inLanguage: 'en',
accessMode: 'textual',
accessModeSufficient: 'textual',
isAccessibleForFree: true,
isPartOf: `${base}libraries/${library}`,
hasPart: Object.entries(tutorials).map(d => ({
'@type': 'TechArticle',
name: d[1].name,
url: `${base}libraries/${library}/tutorials/${d[0]}`,
})),
publisher: {
'@type': 'Organization',
name: 'cdnjs',
url: base,
},
sourceOrganization: {
'@type': 'Organization',
name: 'cdnjs',
url: base,
},
});
16 changes: 16 additions & 0 deletions data/json-ld/website.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export default base => JSON.stringify({
'@context': 'http://schema.org',
'@type': 'WebSite',
name: 'cdnjs',
alternateName: 'CDNJS',
description: 'The #1 free and open source CDN built to make life easier for developers',
logo: `${base}favicon.png`,
thumbnailUrl: `${base}banner.png`,
url: base,
sameAs: ['https://github.com/cdnjs', 'https://twitter.com/cdnjs', 'https://linkedin.com/company/cdnjs'],
potentialAction: {
'@type': 'SearchAction',
target: `${base}libraries?&q={query}`,
query: 'required',
},
});

0 comments on commit 6f08bf3

Please sign in to comment.