- Install the script in Tampermonkey
- Create a new post
- Once you're in the edit block, just use CTRL-V.
Created
March 9, 2022 15:56
-
-
Save brahimmachkouri/8d84843c66fcc340b195fc2778df5d01 to your computer and use it in GitHub Desktop.
Tampermonkey usercript for pasting the "front matter" block in a github post
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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