Skip to content

Instantly share code, notes, and snippets.

@RichardJohnn
Created February 11, 2021 14:06
Show Gist options
  • Save RichardJohnn/9cfcbe0077d35b2641b19a8d47a74676 to your computer and use it in GitHub Desktop.
Save RichardJohnn/9cfcbe0077d35b2641b19a8d47a74676 to your computer and use it in GitHub Desktop.
post pretty URLs to super
const fs = require("fs");
const cheerio = require("cheerio");
const fetch = require("node-fetch");
const path = require( 'path' );
// Make an async function that gets executed immediately
(async ()=> {
const files = await fs.promises.readdir("./");
const prettyUrls = new Set()
for( const file of files) {
const stat = await fs.promises.stat(file);
if(stat.isDirectory())
continue;
const html = fs.readFileSync(file).toString();
const $ = cheerio.load(html);
const contents = $('h1').contents()[0];
if (!contents) continue;
const url = contents.data
.toLowerCase()
.replace(/ /g, '-')
.replace(/--/g, '-')
.replace(/[^0-9a-z-]/gi, '')
.replace(/-$/gi, '')
.replace(/^-/gi, '')
const pushIt = {pageId: file, url};
if (
url == file
|| file.includes('-')
|| file.includes('.')
) {
console.log(url, 'was done already');
continue;
}
console.log(file, url);
prettyUrls.add(pushIt)
}
const body = {
domainName: 'help.vercel.app',
userId: 'badbad37-ae9c-464c-8175-10257f81d1b9',
name: 'Help',
type: 'static',
notionPage: 'https://www.notion.so/blobasdfhsdajfhasd',
active: true,
deployed: true,
status: 'DNS',
version: '1.6.0',
updatedAt: '2021-02-09T15:59:22.786Z',
createdAt: '2021-02-03T21:33:16.899Z',
prettyUrls: Array.from(prettyUrls)
}
console.log(prettyUrls.size);
//paste in the request as fetch for node.js and replace the body
const postResult = await fetch("https://api.super.so/static/update", {
"headers": {
"accept": "application/json",
"accept-language": "en-US,en;q=0.9",
"authorization": "Bearer secretsquirrel",
"cache-control": "no-cache",
"content-type": "text/plain;charset=UTF-8",
"pragma": "no-cache",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-site",
"sec-gpc": "1"
},
"referrer": "https://app.super.so/",
"referrerPolicy": "strict-origin-when-cross-origin",
"body": JSON.stringify(body),
"method": "POST",
"mode": "cors"
});
console.log(postResult)
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment