Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue-33 - add script to import content authors #43

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
};
Loading