Skip to content

Commit

Permalink
feat: render critical styles inline
Browse files Browse the repository at this point in the history
  • Loading branch information
zeim839 committed Feb 10, 2024
1 parent 5d51d66 commit 5fbf4b5
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion utils/callbacks.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
const ejs = require('ejs')
const config = require('./config')
const fs = require('node:fs')
const { BlogModel } = require('../model/blog')

const cacheIndexPage = async () => {
const blog = await BlogModel.find({ status: 'published', id: -1 }, null, { limit: 3 }).sort({ date: -1 })
const data = { version: config.VERSION, blog }

// Load critical styles.
let styles = fs.readFileSync('./public/css/common.css', 'utf8')
styles += fs.readFileSync('./public/css/index.css', 'utf8')

const data = { version: config.VERSION, blog, styles }
const indexPageData = { indexPage: '' }
ejs.renderFile('./views/index.ejs', data, { async: false }, (err, str) => {
if (err) {
Expand Down

0 comments on commit 5fbf4b5

Please sign in to comment.