Skip to content

Commit

Permalink
fix: changes to scripts in front matter
Browse files Browse the repository at this point in the history
  • Loading branch information
davidsneighbour committed Feb 27, 2023
1 parent 5a0b55c commit b8c5787
Show file tree
Hide file tree
Showing 6 changed files with 195 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .frontmatter/config/custom/scripts/unsplash.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://frontmatter.codes/config/custom.scripts.schema.json",
"command": "~/.config/nvm/versions/node/v18.12.1/bin/node",
"script": "./assets/frontmatter/scripts/retrieve-unsplash-header-image-info.js",
"script": "./.frontmatter/scripts/retrieve-unsplash-header-image-info.js",
"title": "Retrieve Unsplash image"
}
5 changes: 3 additions & 2 deletions .frontmatter/config/custom/scripts/youtube.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"$schema": "https://frontmatter.codes/config/custom.scripts.schema.json",
"title": "Generate social image for Youtube",
"script": "./.frontmatter/scripts/create-youtube-header-image.js",
"command": "~/.config/nvm/versions/node/v18.12.1/bin/node",
"script": "./assets/frontmatter/scripts/create-youtube-header-image.js",
"title": "Generate social image for Youtube"
"type": "content"
}
2 changes: 1 addition & 1 deletion .frontmatter/content/mediaDb.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{}
{}
1 change: 1 addition & 0 deletions .frontmatter/scripts/download.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

78 changes: 59 additions & 19 deletions .frontmatter/scripts/retrieve-unsplash-header-image-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,70 @@ require('dotenv').config();
const arguments = process.argv;
const fetch = (...args) => import('node-fetch').then(({ default: fetch }) => fetch(...args));

const Fs = require('fs');
const Https = require('https');

/**
* Download a file from the given `url` into the `targetFile`.
*
* @param {String} url
* @param {String} targetFile
*
* @returns {Promise<void>}
*/
async function downloadFile(url, targetFile) {
return await new Promise((resolve, reject) => {
Https.get(url, response => {
const code = response.statusCode ?? 0

if (code >= 400) {
return reject(new Error(response.statusMessage))
}

// handle redirects
if (code > 300 && code < 400 && !!response.headers.location) {
return resolve(
downloadFile(response.headers.location, targetFile)
)
}

// save the file to disk
const fileWriter = Fs
.createWriteStream(targetFile)
.on('finish', () => {
resolve({})
})

response.pipe(fileWriter)
}).on('error', error => {
reject(error)
})
})
};

(async () => {
if (arguments && arguments.length > 0) {
const folderArg = path.dirname(arguments[3]);
const frontmatterArg = arguments[4];
const data = frontmatterArg && typeof frontmatterArg === "string" ? JSON.parse(frontmatterArg) : null;
const imageId = data.unsplash.imageid;
if (arguments && arguments.length > 0) {
const folderArg = path.dirname(arguments[3]);
const frontmatterArg = arguments[4];
const data = frontmatterArg && typeof frontmatterArg === "string" ? JSON.parse(frontmatterArg) : null;


const imageId = data.unsplash.imageid;
console.log(imageId);

const dataFeed = util.format('https://api.unsplash.com/photos/%s?client_id=%s', imageId, process.env.UNSPLASH_ACCESS_KEY);
const writeFilePromise = util.promisify(fs.writeFile);
const dataFeed = util.format('https://api.unsplash.com/photos/%s?client_id=%s', imageId, process.env.UNSPLASH_ACCESS_KEY);
const writeFilePromise = util.promisify(fs.writeFile);

async function downloadFile(url, outputPath) {
const x = await fetch(url);
const x_1 = await x.arrayBuffer();
return await writeFilePromise(outputPath, Buffer.from(x_1));
}
console.log(dataFeed);

const dataFile = './data/dnb/kollitsch/unsplash/' + imageId + '.json';
downloadFile(dataFeed, dataFile);
const dataFile = './data/dnb/unsplash/' + imageId + '.json';
await downloadFile(dataFeed, dataFile);

let rawdata = fs.readFileSync(dataFile);
let imageData = JSON.parse(rawdata);
downloadFile(imageData.urls.full, folderArg + "/header.jpg");
let rawdata = fs.readFileSync(dataFile);
let imageData = JSON.parse(rawdata);
await downloadFile(imageData.urls.full, folderArg + "/header.jpg");

console.log('{ "frontmatter": { "bla": "fasel" }}');
console.log('{ "frontmatter": { "bla": "fasel" }}');

}
}
})();
133 changes: 130 additions & 3 deletions frontmatter.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,135 @@
"frontMatter.preview.host": "https://192.168.1.201:1313",
"frontMatter.site.baseURL": "https://kollitsch.dev",
"frontMatter.content.publicFolder": "static",
"frontMatter.content.supportedFileTypes": ["md"],
"frontMatter.content.supportedFileTypes": [
"md"
],
"frontMatter.taxonomy.dateFormat": "yyyy-MM-dd'T'H:mm:ssxxx",
"frontMatter.taxonomy.indentArrays": false,
"frontMatter.taxonomy.noPropertyValueQuotes": ["date"]
}
"frontMatter.taxonomy.noPropertyValueQuotes": [
"date"
],
"frontMatter.content.pageFolders": [
{
"path": "[[workspace]]/content"
}
],
"frontMatter.taxonomy.tags": [
"100DaysToOffload",
"CSP",
"EFI",
"SRI",
"UEFI",
"acer",
"alexa",
"automation",
"bash",
"ben-lukas-boysen",
"cat",
"ci",
"code quality",
"component",
"configuration",
"content",
"danny kreutzfeldt",
"database",
"dateformat",
"davidsneighbour",
"debugging",
"deep core",
"design",
"developer fonts",
"developers",
"development",
"dog",
"dotfiles",
"dreamhost",
"earth",
"electron",
"encryption",
"feature",
"frontmatter",
"game-off",
"giscus",
"git",
"github",
"gitignore",
"gitlab",
"gohugo",
"golang",
"google",
"how i work",
"how to",
"howto",
"html",
"javascript",
"keybase",
"laboratory",
"learning",
"leenalchi",
"link",
"links",
"linting",
"logging",
"logos",
"mastodon",
"me now",
"media",
"mike myers",
"movies",
"nagging",
"newsletter",
"nine inch nails",
"notes",
"opsec",
"ordinals",
"piano",
"pipes",
"planning",
"plugin",
"pre-commit",
"privacy",
"programming-music",
"project-management",
"projects",
"queensryche",
"quicklink",
"quicktip",
"rammstein",
"reference",
"render-hook",
"security",
"self-improvement",
"selfimprovement",
"seo",
"shell",
"shortcode",
"social media",
"static websites",
"syntaxhighlighting",
"tag1",
"tag2",
"tag3",
"today i learned",
"todo",
"tok",
"trailers",
"trent reznor",
"troubleshooting",
"twitter",
"typography",
"ubuntu",
"updraftplus",
"useful",
"video",
"vscode",
"web development",
"webdesign",
"wordpress"
],
"frontMatter.taxonomy.categories": [
"components",
"notes-from-the-laboratory",
"wordpress"
]
}

0 comments on commit b8c5787

Please sign in to comment.