Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy demo site on Cloudflare Pages #6

Merged
merged 1 commit into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 14 additions & 39 deletions package-lock.json

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

43 changes: 35 additions & 8 deletions packages/demo-site/config/eleventy.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// const path = require('node:path')
const fs = require('node:fs')
const path = require('node:path')
const slugify = require('slugify')
const navigation = require('@11ty/eleventy-navigation')
const { telegramPlugin } = require('@jackdbd/eleventy-plugin-telegram')
Expand All @@ -8,8 +9,6 @@ const {
const helmet = require('eleventy-plugin-helmet')
const shortcodes = require('../src/shortcodes')

const isProduction = () => process.env.NODE_ENV === 'production'

// add a dev server as soon as it is available in Eleventy 2.0
// https://www.11ty.dev/docs/watch-serve/

Expand Down Expand Up @@ -54,21 +53,49 @@ module.exports = function (eleventyConfig) {
textAfterBuild: `<i>demo-site</i> build <b>FINISHED</b>`
})

// const ELEVENTY_ENV = process.env.ELEVENTY_ENV
// https://developers.cloudflare.com/pages/platform/build-configuration/#environment-variables
console.log('=== ENVIRONMENT ===', {
CF_PAGES: process.env.CF_PAGES,
CF_PAGES_BRANCH: process.env.CF_PAGES_BRANCH,
CF_PAGES_COMMIT_SHA: process.env.CF_PAGES_COMMIT_SHA,
CF_PAGES_URL: process.env.CF_PAGES_URL,
ELEVENTY_ENV: process.env.ELEVENTY_ENV,
NODE_ENV: process.env.NODE_ENV
})

let keyFilename
if (process.env.CF_PAGES) {
keyFilename = 'sa-storage-uploader.json'
// on Cloudflare Pages, GOOGLE_APPLICATION_CREDENTIALS is a JSON string, so
// we need to write it to a file. I think this works automatically on GitHub
// actions (using a GitHub secret), but I tried and it seems it is not
// working automatically on Cloudflare Pages.
fs.writeFile(
keyFilename,
process.env.GOOGLE_APPLICATION_CREDENTIALS,
(err) => {
if (err) {
console.log(`=== ERROR ===${err.message}`)
}
}
)
} else {
// on my laptop, GOOGLE_APPLICATION_CREDENTIALS is a filepath
keyFilename = process.env.GOOGLE_APPLICATION_CREDENTIALS
}

const audioHost = isProduction()
? 'https://undici.pages.dev'
const audioHost = process.env.CF_PAGES_URL
? process.env.CF_PAGES_URL
: 'http://localhost:8090'

eleventyConfig.addPlugin(textToSpeechPlugin, {
audioAssetsDir: 'assets/audio',
audioEncoding: 'MP3',
// audioEncoding: 'LINEAR16',
audioHost,
cloudStorageBucket: 'bkt-eleventy-plugin-text-to-speech-audio-files',
cssSelector: 'div.audio-demos',
// regexPattern: '.*/posts/.*.html$',
keyFilename: process.env.GOOGLE_APPLICATION_CREDENTIALS,
keyFilename,
voice: { languageCode: 'en-GB', name: 'en-GB-Wavenet-C' }
})

Expand Down
4 changes: 2 additions & 2 deletions packages/demo-site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
"dependencies": {
"@11ty/eleventy": "^1.0.1",
"@11ty/eleventy-navigation": "^0.3.3",
"@jackdbd/eleventy-plugin-telegram": "*",
"@jackdbd/eleventy-plugin-text-to-speech": "*",
"@jackdbd/eleventy-plugin-telegram": "1.0.0-alpha.1",
"@jackdbd/eleventy-plugin-text-to-speech": "1.0.0-alpha.2",
"eleventy-plugin-helmet": "^0.2.2"
},
"peerDependencies": {},
Expand Down