Skip to content

Commit

Permalink
translated content should dump the rendered HTML (#1306)
Browse files Browse the repository at this point in the history
Fixes #1305
  • Loading branch information
peterbe authored Sep 22, 2020
1 parent 0bd74f5 commit c8de065
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
17 changes: 10 additions & 7 deletions content/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,20 @@ function getFolderPath(metadata) {
);
}

function archive(renderedHTML, rawHTML, metadata, wikiHistory) {
function archive(renderedHTML, rawHTML, metadata, isTranslatedContent = false) {
const root = isTranslatedContent
? CONTENT_TRANSLATED_ROOT
: CONTENT_ARCHIVED_ROOT;
if (!CONTENT_ARCHIVED_ROOT) {
throw new Error("Can't archive when CONTENT_ARCHIVED_ROOT is not set");
}
if (isTranslatedContent && !CONTENT_TRANSLATED_ROOT) {
throw new Error(
"Can't archive translated content when CONTENT_TRANSLATED_ROOT is not set"
);
}
const folderPath = buildPath(
path.join(CONTENT_ARCHIVED_ROOT, metadata.locale.toLowerCase()),
path.join(root, metadata.locale.toLowerCase()),
metadata.slug
);

Expand All @@ -113,11 +121,6 @@ function archive(renderedHTML, rawHTML, metadata, wikiHistory) {
// the document if we decide to NOT archive it in the future.
fs.writeFileSync(path.join(folderPath, "raw.html"), trimLineEndings(rawHTML));

fs.writeFileSync(
getWikiHistoryPath(folderPath),
JSON.stringify(wikiHistory, null, 2)
);

saveHTMLFile(
getHTMLPath(folderPath),
trimLineEndings(renderedHTML),
Expand Down
7 changes: 4 additions & 3 deletions import/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -990,12 +990,14 @@ async function processDocument(
}

localeWikiHistory.set(doc.slug, wikiHistory);
if (isArchive) {
if (isArchive || doc.locale !== "en-US") {
Document.archive(
getCleanedRenderedHTML(doc.rendered_html),
doc.html,
meta,
wikiHistory
// The Document.archive() is used for genuinely archived content,
// but we also treat translated content the same way ultimately.
!isArchive
);
} else {
Document.create(getCleanedKumaHTML(doc.html), meta);
Expand Down Expand Up @@ -1110,7 +1112,6 @@ async function saveWikiHistory(allHistory, isArchive) {
: CONTENT_TRANSLATED_ROOT;
const localeFolder = path.join(root, locale.toLowerCase());
const filePath = path.join(localeFolder, "_wikihistory.json");
console.log(filePath); // XXX TEMPORARY
const obj = Object.create(null);
const keys = Array.from(history.keys());
keys.sort();
Expand Down

0 comments on commit c8de065

Please sign in to comment.