Skip to content

Instantly share code, notes, and snippets.

@kadamwhite
Last active August 1, 2017 21:23
Show Gist options
  • Save kadamwhite/551fc4ebfbfb09a7769945fc2cb9d6a9 to your computer and use it in GitHub Desktop.
Save kadamwhite/551fc4ebfbfb09a7769945fc2cb9d6a9 to your computer and use it in GitHub Desktop.
"guess" at author mappings when importing WordPress WXR file
[...document.getElementById('authors').querySelectorAll('li')].forEach(li => {
const author = li.querySelector('strong').innerText;
const select = li.querySelector('select');
const options = [...select.querySelectorAll('option')].map(node => ({
value: node.value,
name: node.text,
}));
const match = options.reduce((match, option) => {
if (match) {
return match;
}
return author.indexOf(option.name) > -1 ? option.value : null;
}, null);
if (match) {
select.value = match;
} else {
console.log(`Could not match ${author}`);
}
});
@kadamwhite
Copy link
Author

Consider adding this as a feature to the name mapping screen of https://github.com/humanmade/WordPress-Importer ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment