Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brahimmachkouri/8d84843c66fcc340b195fc2778df5d01 to your computer and use it in GitHub Desktop.
Save brahimmachkouri/8d84843c66fcc340b195fc2778df5d01 to your computer and use it in GitHub Desktop.
Tampermonkey usercript for pasting the "front matter" block in a github post
  1. Install the script in Tampermonkey
  2. Create a new post
  3. Once you're in the edit block, just use CTRL-V.
// ==UserScript==
// @name front_matter_block_github_blog
// @namespace brahimmachkouri
// @version 0.1
// @description Paste the "Front Matter" block for Github blogs : go in the edit post and CTRL-V
// @author Brahim Machkouri
// @include https://github.com/*/new/main/_posts
// @grant GM_setClipboard
// @match none
// ==/UserScript==
(function() {// 2022-03-09
'use strict';
const date = formatDate(new Date())+ ' ' + formatHour(new Date());
console.log("yes");
const header = "---\n\
layout: post\n\
date: "+ date + "\n\
title: \n\
category: \n\
tags: \n\
---\n\
";
document.querySelector('input[name="filename"]').value = formatDate(new Date()) + "-title.md";
GM_setClipboard (header);
function padTo2Digits(num) {
return num.toString().padStart(2, '0');
}
function formatDate(date) {
return (
[
date.getFullYear(),
padTo2Digits(date.getMonth() + 1),
padTo2Digits(date.getDate()),
].join('-')
);
}
function formatHour(date) {
return ([
padTo2Digits(date.getHours()),
padTo2Digits(date.getMinutes()),
padTo2Digits(date.getSeconds()),
].join(':')
);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment