-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathseo-plugins.ts
More file actions
134 lines (121 loc) · 3.23 KB
/
seo-plugins.ts
File metadata and controls
134 lines (121 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import { meta } from "./meta";
type SerializedPage = {
url: string;
changefreq:
| `always`
| `hourly`
| `daily`
| `weekly`
| `monthly`
| `yearly`
| `never`;
priority: 0.0 | 0.1 | 0.2 | 0.3 | 0.4 | 0.5 | 0.6 | 0.7 | 0.8 | 0.9 | 1.0;
lastmod: string;
};
type GatsbyPluginSitemapPage = { path: string };
const legacyRoutes = {
documents: {
preview: `/docs/preview/`,
browse: `/docs/browse/`,
},
};
const disallowedPaths = [
meta.routes.documents.preview,
meta.routes.notFound,
meta.routes.userProfile.preview,
meta.routes.creator.preview,
meta.routes.sandbox,
meta.routes.mindmaps.preview,
meta.routes.assets.management,
meta.routes.likedResources.management,
meta.routes.completed.management,
meta.routes.accessGroups.management,
meta.routes.documents.management,
meta.routes.mindmaps.management,
legacyRoutes.documents.preview,
legacyRoutes.documents.browse,
];
const seoPlugins = () =>
[
{
resolve: `gatsby-plugin-robots-txt`,
options: {
host: meta.siteUrl,
sitemap: `${meta.siteUrl}/sitemap-index.xml`,
policy: [
{
userAgent: `*`,
allow: [`/`],
disallow: [disallowedPaths],
},
],
},
},
{
resolve: `gatsby-plugin-sitemap`,
options: {
query: `
{
allSitePage {
nodes {
path
}
}
}
`,
resolveSiteUrl: (): string => meta.siteUrl,
resolvePages: (payload: {
allSitePage: { nodes: GatsbyPluginSitemapPage[] };
}): GatsbyPluginSitemapPage[] =>
payload.allSitePage.nodes.filter((page) => {
// When "true" returned then it adds page to sitemap
const isDisallowedPath = disallowedPaths.includes(page.path);
if (isDisallowedPath) {
return false;
}
const isEducationZonePage = page.path.startsWith(
meta.routes.education.zone,
);
const isEducationSubPage =
isEducationZonePage && page.path !== meta.routes.education.zone;
if (isEducationSubPage) {
return false;
}
return true;
}),
serialize: ({ path: url }: { path: string }): SerializedPage => {
const lowPrioPaths = [meta.routes.privacyPolicy];
const mediumPrioPaths = [
meta.routes.home,
meta.routes.education.zone,
meta.routes.education.rank,
meta.routes.mindmaps.creator,
];
const lastmod = new Date().toISOString();
if ((lowPrioPaths as string[]).includes(url)) {
return {
url,
lastmod,
changefreq: `monthly`,
priority: 0.5,
};
}
if ((mediumPrioPaths as string[]).includes(url)) {
return {
url,
lastmod,
changefreq: `weekly`,
priority: 0.8,
};
}
return {
url,
lastmod,
changefreq: `daily`,
priority: 1.0,
};
},
},
},
] as const;
export { seoPlugins };