Skip to content

Instantly share code, notes, and snippets.

@BoDonkey
BoDonkey / sort-json-keys.js
Created March 12, 2025 12:44
Node.js gist to alphabetize translation key:string value pairs in JSON files
const fs = require('fs');
const path = require('path');
/**
* Sorts the keys of a JSON object alphabetically and returns a new sorted object
*
* @param {Object} obj - The JSON object to sort
* @returns {Object} - A new object with sorted keys
*/
function sortObjectKeys(obj) {
@BoDonkey
BoDonkey / sync-translations.js
Created March 12, 2025 10:28
Node.js process for comparing and translating missing key:string values in two JSON files
const fs = require('fs');
const path = require('path');
const https = require('https');
/**
* Translates text using Google Translate API (free method)
*
* @param {string} text - Text to translate
* @param {string} targetLang - Target language code (e.g., 'es', 'fr', 'de')
* @returns {Promise<string>} - Translated text
@BoDonkey
BoDonkey / analyze-css.js
Created January 28, 2025 13:11
Code for analyzing CSS created by the Astro build process - useful in debugging postcss extensions
/**
* CSS Build Analyzer
*
* Analyzes CSS files in an Astro build output directory, generating statistics and
* processed versions for analysis.
*
* Usage:
* 1. Place this script in your Astro project
* 2. Run after building: node analyze-css.js
*
@BoDonkey
BoDonkey / iconsList.txt
Created June 15, 2023 09:58
List of icons in Vue-material-design-icons v4.12.1
AbTesting
Abacus
AbjadArabic
AbjadHebrew
AbugidaDevanagari
AbugidaThai
AccessPoint
AccessPointCheck
AccessPointMinus
AccessPointNetwork
@BoDonkey
BoDonkey / index.js
Created March 30, 2023 21:00
Adds testing for a forbidden schema name of "type"- code gets inserted after line 181 of `/piece-type/index.js`
const badFieldName = Object.keys(self.fields).indexOf('type') !== -1;
if (badFieldName) {
throw new Error('@apostrophecms/piece-type field property name cannot be "type"');
}
@BoDonkey
BoDonkey / pieces-malformed.js
Created March 30, 2023 20:55
test to check if the schema field is forbidden
const t = require('../test-lib/test.js');
const assert = require('assert');
let apos;
const apiKey = 'this is a test api key';
describe('Pieces malformed', function () {
this.timeout(t.timeout);
after(async function () {
@BoDonkey
BoDonkey / index.js
Created March 12, 2023 12:44
Webpack options to use vue2 front-end components in ApostropheCMS
const VueLoaderPlugin = require('vue-loader/lib/plugin');
const path = require('path');
module.exports = {
// When not in production, refresh the page on restart
options: {
refreshOnRestart: true
},
webpack: {
extensions: {
@BoDonkey
BoDonkey / middleware.js
Created January 20, 2023 20:44
Middleware for redirecting based on locale
module.exports = {
...
middleware(self, options) {
return {
checkLanguage(req, res, next) {
// if you are only doing this for the homepage, check that is the page being requested
// possibly using req.originalUrl or the url property
// https://v3.docs.apostrophecms.org/reference/module-api/module-overview.html#middleware-self
// make sure
// if not a page you need to redirect just return next()
@BoDonkey
BoDonkey / translation.js
Created December 15, 2022 18:18
Translates an i18n JSON file to a different language
const fs = require('fs').promises;
const translate = require('google-translate-api-x');
async function translateIt(file) {
try {
// read file and parse it as JSON
const data = await fs.readFile(file, 'utf8');
const obj = JSON.parse(data);
// prepare an array of translation keys and an array of translation strings
@BoDonkey
BoDonkey / ColorPicker.vue
Created December 5, 2022 10:32
Vue color picker code written by chatGPT
// Define the component
Vue.component('gradient-picker', {
// The component's options go here
data() {
return {
angle: 0, // The angle of the gradient
colors: [ // An array of objects representing the gradient's colors
{
color: '#000000', // The color's hex code
start: 0, // The color's start position in the gradient (as a percentage)