This code updates a GitHub Gist with modified web page content, likely scraped from a URL, and tracks changes made to the HTML.
npm run import -- "save git"
var importer = require('../Core')
var updateGist = importer.import("write gist files")
async function gitSave(url, data, gist) {
if(!gist) return {}
if(typeof url == 'string') {
url = new URL(url);
}
//console.log(url)
var host = url.hostname.replace(/[^a-z0-9_-]/ig, '_')
var file = url.pathname.replace(/[^a-z0-9_-]/ig, '_')
// check if the file exists
const saved = (await getGist(gist)).files
var acl
if(typeof saved[file] === 'undefined') {
var files = await loadScraped(url)
var changes = {}
changes[file] = {content: files[file]}
if(files[file]) {
await updateGist(gist, files)
}
}
// add changes to gist
var changes = {}
changes[file] = {content: data}
await updateGist(gist, files)
// diff the HTML for changes
const changes = []
if(saved && saved[host + '-acl.json']) {
var acl = files[host + '-acl.json'] || []
if(typeof acl === 'string') {
acl = [acl]
}
var bodyPrevious = selectDom('//body', saved[file])
var bodyNew = selectDom('//body', data)
acl.forEach(i => {
var before = selectDom([i], bodyPrevious)
var after = selectDom([i], bodyNew)
})
}
// save the changes to spreadsheet
}
module.exports = gitSave
/**
* Saves data to a gist on GitHub.
*
* @param {string} url - The URL of the gist.
* @param {object} data - The data to save to the gist.
* @param {string} gist - The ID of the gist to update.
* @returns {Promise
This code defines a function gitSave
that updates a GitHub Gist with modified content, likely from a web page scraping process.
Here's a breakdown:
Dependencies:
updateGist
responsible for updating the Gist content.gitSave
Function:
url
, data
(presumably the updated content), and gist
(Gist information) as arguments.loadScraped
(not shown in the snippet), creates a new file entry, and updates the Gist.data
for the specified file.Export:
gitSave
function is exported as a module.Overall Purpose:
This code snippet appears to be part of a system that scrapes web pages, modifies their content, and then saves the changes to a GitHub Gist. It also attempts to track and potentially report the changes made to the HTML content.