-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
nuxt.config.js
186 lines (172 loc) · 6.86 KB
/
nuxt.config.js
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import "consola";
import fetch from "node-fetch"
if (process.env.NODE_ENV === "development") {
consola.info(
"Hello, and thanks for having interest in my site. However, I am not accepting contributions, as this is my personal site, and my project. If you want to contribute to something, find another open source project that needs your help. \n~ GrahamSH"
);
}
import tailwindTypography from "@tailwindcss/typography";
import lineClamp from "tailwindcss-line-clamp";
const createSitemapRoutes = async () => {
let routes = [];
const { $content } = require("@nuxt/content");
let posts = await $content("blog").fetch();
posts.forEach((post) => {
console.log(post);
routes.push(`blog/${post.slug}`);
});
return routes;
};
export default {
ssr: false,
telemetry: false,
// Target: https://go.nuxtjs.dev/config-target
target: "static",
generate: {
async routes() {
const { $content } = require("@nuxt/content");
const files = await $content({ deep: true }).only(["path"]).fetch();
return files.map((file) => (file.path === "/index" ? "/" : file.path));
},
},
// Global page headers: https://go.nuxtjs.dev/config-head
head: {
title: "GrahamSH",
htmlAttrs: {
lang: "en",
},
meta: [
{ charset: "utf-8" },
{ name: "viewport", content: "width=device-width, initial-scale=1" },
{ hid: "description", name: "description", content: "" },
],
link: [{ rel: "icon", type: "image/x-icon", href: "/logo.svg" }],
},
tailwindcss: {
config: {
mode: "jit",
plugins: [tailwindTypography, lineClamp],
theme: {
screens: {
sm: "640px",
md: "768px",
lg: "1024px",
xl: "1280px",
},
},
},
},
// Auto import components: https://go.nuxtjs.dev/config-components
components: true,
pwa: {
icons: {
source: `[srcDir]/[staticDir]/logo.svg`,
},
},
// Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
buildModules: [
// https://go.nuxtjs.dev/tailwindcss
"@nuxtjs/tailwindcss",
"@nuxtjs/pwa",
"@nuxtjs/svg",
],
workbox: {
runtime: [
{
urlPattern: "https://fonts.gstatic.com/.*",
handler: "staleWhileRevalidate",
},
{
urlPattern: ".*",
handler: "staleWhileRevalidate",
},
],
},
// Modules: https://go.nuxtjs.dev/config-modules
modules: ["@nuxt/content", "@nuxtjs/sitemap", "vue-plausible", '@nuxtjs/feed', "@nuxtjs/markdownit",'@nuxtjs/critters',],
plausible: {
domain: "grahamsh.com",
apiHost: "https://analytics.jeffalo.net",
},
// Build Configuration: https://go.nuxtjs.dev/config-build
build: {
//parallel: true,
},
sitemap: {
hostname: "https://grahamsh.com",
gzip: true,
routes: createSitemapRoutes,
exclude: ["/blogs/**"],
},
plugins: ["~/plugins/json-ld", "~/plugins/unicons"],
storybook: {
stories: ["~/components/**/*.stories.mdx"],
addons: ["@storybook/addon-docs"],
parameters: {
//viewMode: 'docs'
},
},
feed: [
{
// this sets up where to find your rss feed - mine will be called feed.xml, and located in the root of my project
path: '/feed.xml',
// this function will be what sets the data that goes into feed.xml
async create(feed) {
// the main options of what the page is called, desc, and where to find it as a full path
feed.options = {
title: 'Blog - GrahamSH',
description: 'Code notes and other assorted goodies from GrahamSH',
link: 'https://grahamsh.com/feed.xml',
};
// we're going to require the content module so we have access to $content, then we're going to fetch all of our posts. If you're using eslint in your project, you might need to ignore this line because it's requiring something inside a function. Will work just fine, it might yell at you though. :)
// eslint-disable-next-line global-require
const { $content } = require('@nuxt/content');
// get all the posts we have
const posts = await $content('blog').fetch();
// then, we'll loop over each post and grab the data fields we want to show in our feed. The name of your fields might be different than mine - that depends on how your data is set up in your Content settings.
posts.forEach(async (post) => {
// the url of the post is set first
const url = `https://grahamsh.com/blog/${post.slug}`;
// then we do addItem, and give it all the details we want. You'll often see a date field here too - I don't have one because I don't post my dates on my posts.
feed.addItem({
title: post.title,
id: url,
link: url,
description: post.blurb,
date: new Date(post.date),
// this is what we did in part two! Accessing that body text, that we converted into HTML
content: post.bodyText,
});
});
}, // this is the end of the create function
// cacheTime sets how long the feed is cached - this is what they had in the feed-module example, and I've left it as is for now. Type sets what kind of feed it is - you can do atom or json as well.
cacheTime: 1000 * 60 * 15,
type: 'rss2',
},
], // this is the end of the feed settings
// This is our hook! We check if the document is a markdown file (meaning it's a blog post in this case), and if so we get the reading time and set it to a property on the document, and also set our plain text of the post to a property.
hooks: {
'content:file:beforeInsert': (document) => {
// first, we're going to bring in our markdownit file - in JS, it's written as markdown-it, but in the package.json and modules bit, there's no dash - hence the eslint-disable line. It will work fine - it just doesn't get that the package name is written differently
// eslint-disable-next-line
const md = require('markdown-it')();
if (document.extension === '.md') {
// ignoring eslint again :) same warning as earlier
// eslint-disable-next-line global-require
const { text } = require('reading-time')(document.text);
document.readingTime = text;
// Now we pass our post's plain text into the md.render file, which will convert it into HTML
// Then we store that value in our bodyText variable on our post
const mdToHtml = md.render(document.text);
document.bodyText = mdToHtml;
}
},
}, // end of the hook setting
// We'll also need to add in some default settings for the markdown-it package - this part I don't quite understand yet as far as what everything's doing, they're just the default settings listed on the package's GitHub page
markdownit: {
preset: 'default',
linkify: true,
breaks: true,
use: ['markdown-it-div', 'markdown-it-attrs'],
},
};