Skip to content

Commit

Permalink
issue-33 - add script to import content authors
Browse files Browse the repository at this point in the history
  • Loading branch information
tmaret committed Dec 13, 2023
1 parent c003633 commit 5a4993b
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions tools/importer/import-author.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright 2023 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

export default {
/**
* Apply DOM operations to the provided document and return
* the root element to be then transformed to Markdown.
* @param {HTMLDocument} document The document
* @param {string} url The url of the page imported
* @param {string} html The raw html (the document is cleaned up during preprocessing)
* @param {object} params Object containing some parameters given by the import process.
* @returns {HTMLElement} The root element to be transformed
*/
transformDOM: ({
// eslint-disable-next-line no-unused-vars
document, url, html, params,
}) => {
const main = document.body;
WebImporter.DOMUtils.remove(main, [

Check failure on line 28 in tools/importer/import-author.js

View workflow job for this annotation

GitHub Actions / build

'WebImporter' is not defined
'noscript',
]);
const contributor = main.querySelector('.contributorBlock');
// upgrade title to h3 tag
const title = contributor.querySelector('.name > p');
const h3 = document.createElement('h3');
h3.innerHTML = title.innerHTML;
title.replaceWith(h3);
return contributor;
},

/**
* Return a path that describes the document being transformed (file name, nesting...).
* The path is then used to create the corresponding Word document.
* @param {HTMLDocument} document The document
* @param {string} url The url of the page imported
* @param {string} html The raw html (the document is cleaned up during preprocessing)
* @param {object} params Object containing some parameters given by the import process.
* @return {string} The path
*/
generateDocumentPath: ({
// eslint-disable-next-line no-unused-vars
document, url, html, params,
}) => WebImporter.FileUtils.sanitizePath(new URL(url).pathname.replace(/\.html$/, '').replace(/\/$/, '')),

Check failure on line 52 in tools/importer/import-author.js

View workflow job for this annotation

GitHub Actions / build

'WebImporter' is not defined
};

0 comments on commit 5a4993b

Please sign in to comment.