Skip to content
This repository has been archived by the owner on Feb 13, 2025. It is now read-only.

Commit

Permalink
MWPW-141282 Update UK/AU Blog Tag (#31)
Browse files Browse the repository at this point in the history
* MWPW-141282 Update UK/AU Blog Tag

* update fs imports
  • Loading branch information
meganthecoder authored Feb 6, 2024
1 parent d329c92 commit ab77332
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 32 deletions.
15 changes: 11 additions & 4 deletions bacom-blog/article-feed/article-feed.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,15 @@ function getFeedRow(feedURL) {
type: 'paragraph',
children: [
{
type: 'text',
value: feedURL,
type: 'link',
title: null,
url: feedURL,
children: [
{
type: 'text',
value: feedURL,
},
],
},
],
},
Expand All @@ -49,8 +56,8 @@ export default function updateArticleFeed(mdast, entry) {
const UK_PATH = '/uk/blog/';
let feedURL;

if (entry.includes(AU_PATH)) feedURL = 'https://main--bacom-blog--adobecom.hlx.page/au/us-au-query-index.json';
if (entry.includes(UK_PATH)) feedURL = 'https://main--bacom-blog--adobecom.hlx.page/uk/us-uk-query-index.json';
if (entry.includes(AU_PATH)) feedURL = 'https://main--bacom-blog--adobecom.hlx.page/au/blog/us-au-query-index.json';
if (entry.includes(UK_PATH)) feedURL = 'https://main--bacom-blog--adobecom.hlx.page/uk/blog/us-uk-query-index.json';
if (!feedURL) {
return {
status: STATUS_SKIPPED,
Expand Down
14 changes: 8 additions & 6 deletions blog-migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* governing permissions and limitations under the License.
*/

import { writeFile, mkdir, access } from 'fs/promises';
import * as fs from 'fs';
import xlsx from 'xlsx';
import { getMdast, getTableMap } from './utils/mdast-utils.js';
import { saveDocx } from './utils/docx-utils.js';
Expand Down Expand Up @@ -90,8 +90,10 @@ async function createReport(reports, reportFile) {
});

const reportDir = reportFile.substring(0, reportFile.lastIndexOf('/'));
await mkdir(reportDir, { recursive: true });
await xlsx.writeFile(workbook, reportFile);

fs.mkdirSync(reportDir, { recursive: true });
xlsx.set_fs(fs);
xlsx.writeFile(workbook, reportFile);
}

function formatReportData(reports) {
Expand Down Expand Up @@ -272,7 +274,7 @@ async function handleMigration(markdown, entry, pageIndex, outputDir, entries) {

async function ensureDocxFileExists(mdast, sourceDocxFile) {
try {
await access(sourceDocxFile);
fs.accessSync(sourceDocxFile);
} catch (e) {
await saveDocx(mdast, sourceDocxFile);
}
Expand Down Expand Up @@ -320,11 +322,11 @@ export async function main(index = INDEX, source = SOURCE_CACHE, outputDir = OUT

const dateStr = getDateString();
const migrationReportFile = `${REPORT_DIR}/${PROJECT}/Migration ${dateStr}`;
await writeFile(`${migrationReportFile}.json`, JSON.stringify({ reports }, null, 2));
fs.writeFileSync(`${migrationReportFile}.json`, JSON.stringify({ reports }, null, 2));
console.log(`Report written to ${migrationReportFile}.json`);

const linkReportFile = `${REPORT_DIR}/${PROJECT}/Links ${dateStr}`;
await writeFile(`${linkReportFile}.json`, JSON.stringify({ totalLinksReport }, null, 2));
fs.writeFileSync(`${linkReportFile}.json`, JSON.stringify({ totalLinksReport }, null, 2));
console.log(`Report written to ${linkReportFile}.json`);

await createReport(reports, `${migrationReportFile}.xlsx`);
Expand Down
29 changes: 18 additions & 11 deletions test/bacom-blog/article-feed/mocks/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,25 @@
]
},
{
"type": "gtCell",
"type": "gtCell",
"children": [
{
"type": "paragraph",
"children": [
{
"type": "link",
"title": null,
"url": "https://main--bacom-blog--adobecom.hlx.page/au/blog/us-au-query-index.json",
"children": [
{
"type": "paragraph",
"children": [
{
"type": "text",
"value": "https://main--bacom-blog--adobecom.hlx.page/au/us-au-query-index.json"
}
]
}
{
"type": "text",
"value": "https://main--bacom-blog--adobecom.hlx.page/au/blog/us-au-query-index.json"
}
]
}
]
}
]
}
]
}
Expand All @@ -127,4 +134,4 @@
]
}
]
}
}
29 changes: 18 additions & 11 deletions test/bacom-blog/article-feed/mocks/outputUk.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,25 @@
]
},
{
"type": "gtCell",
"type": "gtCell",
"children": [
{
"type": "paragraph",
"children": [
{
"type": "link",
"title": null,
"url": "https://main--bacom-blog--adobecom.hlx.page/uk/blog/us-uk-query-index.json",
"children": [
{
"type": "paragraph",
"children": [
{
"type": "text",
"value": "https://main--bacom-blog--adobecom.hlx.page/uk/us-uk-query-index.json"
}
]
}
{
"type": "text",
"value": "https://main--bacom-blog--adobecom.hlx.page/uk/blog/us-uk-query-index.json"
}
]
}
]
}
]
}
]
}
Expand All @@ -127,4 +134,4 @@
]
}
]
}
}

0 comments on commit ab77332

Please sign in to comment.