The updateInterestPage function updates a Google Sheets document's "Interests" page by retrieving bookmarks, filtering them by categories, and updating the document's rows with the formatted data. This function is exported as a module and, if a $ object is defined, it is executed asynchronously, with results sent to $.sendResult and errors sent to $.sendError.
npm run import -- "update insterests resume sheet"var _ = require('lodash');
var importer = require('../Core');
var getBookmarksFromTakeout = importer.import("parse bookmarks file");
var updateRow = importer.import("update a row in google sheets")
var getDataSheet = importer.import("get google data sheet")
var doc = 'https://docs.google.com/spreadsheets/d/1dAtBQyn5vwStM6ITn7iCpp996Sus26k0bJtbGNlCX2g/edit#gid=257854275';
function updateInterestPage() {
    var links, interests;
    return getDataSheet(doc, 'Interests data')
        .then(rows => interests = rows.map(r => r.category).filter((r, i, arr) => arr.indexOf(r) === i))
        .then(() => getBookmarksFromTakeout())
        .then(l => links = [].concat(...Object.values(l))
              .filter(b => interests.includes(b.folder))
              .map(b => ({
                category: b.folder,
                date: b.time,
                title: b.title,
                link: b.url,
                skills: null,
                tools: null
            })))
        .then(() => importer.runAllPromises(links.map(l => resolve => {
            // category date title link skills tools
            return updateRow(doc, r => {
                return r.category == l.category && !r.link
                             || r.date == l.date && r.link == l.link}, l, 'Interests data')
                .then(resolve);
        })))
}
module.exports = updateInterestPage;
if(typeof $ != 'undefined') {
    $.async();
    
    updateInterestPage()
        .then(r => $.sendResult(r))
        .catch(e => $.sendError(e))
}
const { minBy } = require('lodash');
const importer = require('../Core');
const parseBookmarksFile = importer.import('parse bookmarks file');
const updateRowInGoogleSheets = importer.import('update a row in google sheets');
const getGoogleDataSheet = importer.import('get google data sheet');
const DOCUMENT_ID = 'https://docs.google.com/spreadsheets/d/1dAtBQyn5vwStM6ITn7iCpp996Sus26k0bJtbGNlCX2g/edit#gid=257854275';
/**
 * Updates the Interest page by fetching bookmarks, filtering interests, and updating the sheet.
 *
 * @returns {Promise} A promise resolving with the updated data.
 */
function updateInterestPage() {
    const interests = [];
    const links = [];
    /**
     * Fetches the interests data from the sheet.
     */
    return getGoogleDataSheet(DOCUMENT_ID, 'Interests data')
       .then((rows) => {
            const uniqueInterests = rows.map((r) => r.category).filter((r, i, arr) => arr.indexOf(r) === i);
            interests.push(...uniqueInterests);
            return getBookmarksFromTakeout();
        })
       .then((bookmarks) => {
            links.push(...Object.values(bookmarks)
               .filter((bookmark) => interests.includes(bookmark.folder))
               .map((bookmark) => ({
                    category: bookmark.folder,
                    date: bookmark.time,
                    title: bookmark.title,
                    link: bookmark.url,
                    skills: null,
                    tools: null,
                })));
            // Update rows in the sheet
            return Promise.all(links.map(updateRowInGoogleSheets(DOCUMENT_ID, 'Interests data')));
        })
       .then(() => links);
}
module.exports = updateInterestPage;
if (typeof $!== 'undefined') {
    $.async();
    
    updateInterestPage()
       .then((result) => $.sendResult(result))
       .catch((error) => $.sendError(error));
}Code Breakdown
lodash is imported for functional utilities.importer is a custom module that imports specific functions from another module (../Core).importer:
getBookmarksFromTakeout: parses a bookmarks file.updateRow: updates a row in a Google Sheets document.getDataSheet: retrieves a Google Data Sheet.updateInterestPage FunctiongetDataSheet.getBookmarksFromTakeout.updateRow, passing in the formatted bookmarks data.updateInterestPage function is exported as a module.$ object is defined, the function is executed asynchronously, and the result is sent to the $.sendResult method. If an error occurs, the error is sent to the $.sendError method.