Skip to content

Commit

Permalink
cleanup scripts and workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
jackdbd committed May 4, 2024
1 parent 23bab3a commit d4cf196
Show file tree
Hide file tree
Showing 42 changed files with 559 additions and 644 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ask-hn-freelancer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
run: |
delimiter=$(openssl rand -hex 8)
echo "RESULT_STRING<<$delimiter" >> $GITHUB_ENV
node scripts/hacker-news/post-ad-on-ask-hn-seeking-freelancer.cjs ${{ fromJSON(env.HN_JSON).item_id }} >> $GITHUB_ENV
node scripts/hacker-news/post-ad-on-ask-hn-seeking-freelancer.mjs ${{ fromJSON(env.HN_JSON).item_id }} >> $GITHUB_ENV
echo "$delimiter" >> $GITHUB_ENV
- name: 💬 Notify Telegram of my ad
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Deploy site via Cloudflare Pages deploy hook'
name: 'Cloudflare Pages deploy hook'

on:
schedule:
Expand All @@ -8,7 +8,7 @@ on:
workflow_dispatch:
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#workflow_dispatch
# You can trigger this workflow manually using the GitHub CLI:
# gh workflow run "Deploy site via Cloudflare Pages deploy hook" --ref branch-name
# gh workflow run "Cloudflare Pages deploy hook" --ref branch-name

jobs:
deploy:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/hn-links-to-telegram.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
run: |
delimiter=$(openssl rand -hex 8)
echo "TELEGRAM_MESSAGE<<$delimiter" >> $GITHUB_ENV
node scripts/hacker-news/job-links.cjs -d 'Jobs from YC-backed startups on HN this week' -q 'hacker-news-jobs-YC.sql' >> $GITHUB_ENV
node scripts/hacker-news/job-links.mjs -d 'Jobs from YC-backed startups on HN this week' -q 'hacker-news-jobs-YC.sql' >> $GITHUB_ENV
echo "$delimiter" >> $GITHUB_ENV
- name: 💬 Send Hacker News link to Telegram
Expand Down
101 changes: 0 additions & 101 deletions .github/workflows/linkedin-links-to-telegram.yaml

This file was deleted.

5 changes: 5 additions & 0 deletions .github/workflows/notify-of-workflow-run-conclusion.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ on:
workflows:
- 'Ask HN Freelancer? Seeking Freelancer? (by whoishiring)'
- 'CI'
- 'Cloudflare Pages deploy hook'
- 'Hacker News links to Telegram'
- 'Reddit freelancing'
- 'Reddit search'
- 'Stripe Promotion Codes'
- 'WebPageTest audit'
types: [completed]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: 'Promo Codes'
name: 'Stripe Promotion Codes'

on:
schedule:
# https://crontab.guru/
- cron: '45 13 * * 4'
workflow_dispatch:
# You can trigger this workflow manually using the GitHub CLI:
# gh workflow run "Promo Codes"
# gh workflow run "Stripe Promotion Codes"

jobs:
deploy:
Expand Down
18 changes: 9 additions & 9 deletions config/eleventy.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'node:fs'
import { join } from 'node:path'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import makeDebug from 'debug'
import defDebug from 'debug'
import markdownIt from 'markdown-it'
import markdownItAnchor from 'markdown-it-anchor'
import { EleventyRenderPlugin } from '@11ty/eleventy'
Expand Down Expand Up @@ -29,14 +29,14 @@ import { callout, table } from '../11ty/paired-shortcodes.mjs'
import { htmlmin } from '../11ty/transforms.mjs'
import cloudinaryPlugin from '../plugins/11ty/cloudinary/index.cjs'
import { pagefindPlugin } from '../plugins/11ty/pagefind/index.mjs'
import stripePlugin from '../plugins/11ty/stripe/index.cjs'
import webmentionsPlugin from '../plugins/11ty/webmentions/index.cjs'
import { stripePlugin } from '../plugins/11ty/stripe/index.mjs'
import { webmentionsPlugin } from '../plugins/11ty/webmentions/index.mjs'

const debug = makeDebug(`11ty-config:eleventy.mjs`)
const debug = defDebug(`11ty-config:eleventy.mjs`)

const __filename = fileURLToPath(import.meta.url)
const REPO_ROOT = join(__filename, '..', '..')
const OUTPUT_DIR = join(REPO_ROOT, '_site')
const REPO_ROOT = path.join(__filename, '..', '..')
const OUTPUT_DIR = path.join(REPO_ROOT, '_site')

// shamelessly stolen from:
// https://github.com/maxboeck/mxb/blob/db6ca7743f46cf67367a93c8de404cbcb50b98d1/utils/markdown.js
Expand Down Expand Up @@ -94,7 +94,7 @@ export default function (eleventyConfig) {
// on my NixOS laptop, I have a secret stored on the filesystem
keyFilename = undefined
// on my non-NixOS laptop, I keep the JSON key in the secrets/ directory
// keyFilename = join(REPO_ROOT, 'secrets', 'sa-storage-uploader.json')
// keyFilename = path.join(REPO_ROOT, 'secrets', 'sa-storage-uploader.json')
// process.env.GOOGLE_APPLICATION_CREDENTIALS = keyFilename
}

Expand Down Expand Up @@ -173,7 +173,7 @@ export default function (eleventyConfig) {
stripe_json_string = process.env.STRIPE_LIVE
} else {
stripe_json_string = fs.readFileSync(
join(REPO_ROOT, 'secrets', 'stripe-live.json'),
path.join(REPO_ROOT, 'secrets', 'stripe-live.json'),
{ encoding: 'utf8' }
)
}
Expand Down
4 changes: 2 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@

ARTICLE_SLUG = "test-your-javascript-on-multiple-engines-with-eshost-cli-and-jsvu";
# DEBUG = "Eleventy:UserConfig";
# DEBUG = "Eleventy:EleventyErrorHandler";
DEBUG = "script:*,Eleventy:EleventyErrorHandler,11ty-config:*,11ty-plugin:*,-11ty-plugin:TTS:inject-audio-tags-into-html";
DEBUG = "11ty-plugin:*,Eleventy:EleventyErrorHandler";
# DEBUG = "script:*,Eleventy:EleventyErrorHandler,11ty-config:*,11ty-plugin:*,-11ty-plugin:TTS:inject-audio-tags-into-html";
# DEBUG = "11ty-plugin-cloudinary:*,-11ty-plugin-cloudinary:transforms";
DOMAIN = "giacomodebidda.com";
GOOGLE_APPLICATION_CREDENTIALS = "/run/secrets/prj-kitchen-sink/sa-storage-uploader";
Expand Down
9 changes: 9 additions & 0 deletions plugins/11ty/stripe/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const DEBUG_PREFIX = '11ty-plugin:stripe'

export const ERROR_PREFIX = '[💰 11ty-plugin:stripe]'

export const DEFAULT_STRIPE_CONFIG = {}

export const DEFAULT_PLUGIN_CONFIG = {
stripeConfig: DEFAULT_STRIPE_CONFIG
}
52 changes: 0 additions & 52 deletions plugins/11ty/stripe/index.cjs

This file was deleted.

40 changes: 40 additions & 0 deletions plugins/11ty/stripe/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import defDebug from 'debug'
import Stripe from 'stripe'
import { DEBUG_PREFIX, ERROR_PREFIX } from './constants.mjs'
import { plugin_options, stripe_price_lookup_key } from './schemas.mjs'
import { paymentLinksByPriceLookupKey } from './utils.mjs'

const debug = defDebug(`${DEBUG_PREFIX}:index`)

// TIP: give the plugin configuration function a name, so it can be easily
// spotted in EleventyErrorHandler.
export const stripePlugin = (eleventyConfig, options) => {
const result = plugin_options.safeParse(options)
if (!result.success) {
throw new Error(
`${ERROR_PREFIX} invalid configuration: ${result.error.message}`
)
}

const { apiKey, stripeConfig } = result.data

const matches = apiKey.match(/^sk_test_./)
const is_test = matches ? true : false

const client = new Stripe(apiKey, stripeConfig)

eleventyConfig.addAsyncFilter('stripePaymentLinks', async (lookup_key) => {
stripe_price_lookup_key.parse(lookup_key)

// My plugin is an alternative solution to the original Stripe buy button
// https://stripe.com/docs/payment-links/share#embed-button
const plinks = await paymentLinksByPriceLookupKey({
stripe: client,
is_test,
lookup_key
})

return plinks
})
debug(`added async filter stripePaymentLinks`)
}
12 changes: 12 additions & 0 deletions plugins/11ty/stripe/schemas.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { z } from 'zod'
import { DEFAULT_STRIPE_CONFIG } from './constants.mjs'

// https://stripe.com/docs/api/prices/object#price_object-lookup_key
export const stripe_price_lookup_key = z.string().min(1).max(200)

export const plugin_options = z.object({
// optional, so it can be set with an environment variable
apiKey: z.string().min(1).optional(),

stripeConfig: z.any().default(DEFAULT_STRIPE_CONFIG)
})
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
const makeDebug = require('debug')
import defDebug from 'debug'
import { DEBUG_PREFIX } from './constants.mjs'

const debug = makeDebug('eleventy-plugin-stripe:utils')
const debug = defDebug(`${DEBUG_PREFIX}:utils`)

/**
* https://stripe.com/docs/api/payment_links/payment_links/list
* https://stripe.com/docs/api/payment_links/line_items?lang=node
*/
const paymentLinksByPriceLookupKey = async ({
export const paymentLinksByPriceLookupKey = async ({
stripe,
is_test,
lookup_key
Expand Down Expand Up @@ -49,5 +50,3 @@ const paymentLinksByPriceLookupKey = async ({

return plinks
}

module.exports = { paymentLinksByPriceLookupKey }
31 changes: 31 additions & 0 deletions plugins/11ty/webmentions/constants.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export const DEBUG_PREFIX = '11ty-plugin:webmentions'

export const ERROR_PREFIX = '[💬 11ty-plugin-webmentions]'

export const DEFAULT_BLACKLISTED = []

export const DEFAULT_CACHE_DIRECTORY = '.cache-webmentions'
export const DEFAULT_CACHE_DURATION = '3600s'
export const DEFAULT_CACHE_VERBOSE = false

export const DEFAULT_DOMAIN = undefined

// https://github.com/apostrophecms/sanitize-html#default-options
export const DEFAULT_SANITIZE_OPTIONS = {
allowedTags: ['b', 'i', 'em', 'strong', 'a', 'p'],
allowedAttributes: {
a: ['href']
}
}

export const DEFULT_TOKEN = undefined

export const DEFAULT_PLUGIN_CONFIG = {
blacklisted: DEFAULT_BLACKLISTED,
cacheDirectory: DEFAULT_CACHE_DIRECTORY,
cacheDuration: DEFAULT_CACHE_DURATION,
cacheVerbose: DEFAULT_CACHE_VERBOSE,
domain: DEFAULT_DOMAIN,
sanitizeOptions: DEFAULT_SANITIZE_OPTIONS,
token: DEFULT_TOKEN
}
Loading

0 comments on commit d4cf196

Please sign in to comment.