Skip to content

Instantly share code, notes, and snippets.

@wdzajicek
Created February 24, 2021 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wdzajicek/d1eb1701a9d8a639bb17d1357cfae54a to your computer and use it in GitHub Desktop.
Save wdzajicek/d1eb1701a9d8a639bb17d1357cfae54a to your computer and use it in GitHub Desktop.
Hack a SharePoint 2013 list into individual markdown files w/ YAML front-matter
// Save file as index.js and run with node:
// node index.js
// =================================================================================================================== //
// We have an old SharePoint 2013 site that has over 2,400 articles created with a single sharepoint-list that grew over the years
// We needed to backup all these articles so we could ditch our dying, ancient CMS
// This "hack" was needed to rescue/migrate our massive list from the grips of SharePoint 2013
// =================================================================================================================== //
// To use:
// Create an RSS feed from the SharePoint 2013 list
// Convert the RSS feed into a JS object using an online converter e.g. <https://rsstojson.com>
const fs = require('fs');
// The json was created by running a SharePoint 2013 RSS feed (created from a SharePoint-list) through an RSS to JSON app:
const json = {"rss": {"channel": [{"title":["My Title"], "author": ["someone"], "content":[`<h1>Hello World!</h1>`], "date": ["2/2/2021"], "url": ["https://www.kcc.edu"]},{/*More objects*/},{/*...*/}]}}
const dataArr = json.rss.channel[0].item; // This "item" key holds an array of objects: one object for each RSS item
for (let i = 0, len = dataArr.length; i < len; i++) {
const item = dataArr[i];
const title = item.title.toString();
const author = item.author.toString();
const content = item.description.toString();
const date = item.pubDate.toString();
const url = item.link.toString();
let fileArr = ['---'];
fileArr.push(`\ntitle: ${title}`);
fileArr.push(`\nauthor: ${author}`);
fileArr.push(`\ndate: ${date}`);
fileArr.push(`\nurl: ${url}`);
fileArr.push('\n---');
fileArr.push(`\n${content}`);
const fileString = fileArr.join('');
const file = title.toLowerCase().trim();
const filename = file.replace(/\W/g, '') + '.md';
fs.writeFile(filename, fileString, (err) => {
if (err) throw err;
console.log('The file has been saved!');
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment