ultimate-jekyll-manager 0.0.38 → 0.0.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -72,10 +72,15 @@ async function validateFormat(file, content) {
72
72
  (async () => {
73
73
  try {
74
74
  // Format the content using Prettier
75
- const formatted = await formatDocument(content, format, true);
75
+ const formatted = await formatDocument(content, format);
76
76
 
77
77
  // Save the formatted content back to the file
78
- jetpack.write(file, formatted);
78
+ jetpack.write(file, formatted.content);
79
+
80
+ // Quit if there is an error
81
+ if (formatted.error) {
82
+ throw formatted.error;
83
+ }
79
84
 
80
85
  return { valid: true, messages: [] };
81
86
  } catch (e) {
@@ -148,7 +148,11 @@ async function processTranslation() {
148
148
  // logger.log(allFiles);
149
149
 
150
150
  // Prepare meta caches per language
151
- const metas = {};
151
+ const metas = {
152
+ global: {
153
+ skipped: new Set(),
154
+ }
155
+ };
152
156
  for (const lang of languages) {
153
157
  const metaPath = path.join(CACHE_DIR, lang, 'meta.json');
154
158
  let meta = {};
@@ -159,7 +163,7 @@ async function processTranslation() {
159
163
  logger.warn(`⚠️ Failed to parse meta for [${lang}], starting fresh`);
160
164
  }
161
165
  }
162
- metas[lang] = { meta, path: metaPath, skipped: [] };
166
+ metas[lang] = { meta, path: metaPath, skipped: new Set() };
163
167
  }
164
168
 
165
169
  // Track token usage
@@ -183,9 +187,8 @@ async function processTranslation() {
183
187
 
184
188
  // Skip all except the specified HTML file
185
189
  if (ujOnly && relativePath !== ujOnly) {
186
- for (const lang of languages) {
187
- metas[lang].skipped.push(`${relativePath} (UJ_TRANSLATION_ONLY set)`);
188
- }
190
+ // Update to work with the new SET protocol
191
+ metas.global.skipped.add(`${relativePath} (UJ_TRANSLATION_ONLY set)`);
189
192
  continue;
190
193
  }
191
194
 
@@ -260,6 +263,11 @@ async function processTranslation() {
260
263
  // Log result
261
264
  // console.log('---translated---', translated);
262
265
 
266
+ // Reset the DOM to avoid conflicts between languages
267
+ const $ = cheerio.load(originalHtml);
268
+ // Collect text nodes with tags
269
+ const textNodes = collectTextNodes($, { tag: true });
270
+
263
271
  // Replace original text nodes with translated versions
264
272
  textNodes.forEach((n, i) => {
265
273
  const regex = new RegExp(`\\[${i}\\](.*?)\\[/${i}\\]`, 's');
@@ -294,7 +302,7 @@ async function processTranslation() {
294
302
  $('meta[property="og:url"]').attr('content', canonicalUrl);
295
303
 
296
304
  // Insert language tags on this translation
297
- await insertLanguageTags($, languages, relativePath);
305
+ await insertLanguageTags($, languages, relativePath, outPath);
298
306
 
299
307
  // Insert language tags in original file
300
308
  await insertLanguageTags(cheerio.load(originalHtml), languages, relativePath, filePath);
@@ -305,7 +313,15 @@ async function processTranslation() {
305
313
  await insertLanguageTags(cheerio.load(sitemapXml, { xmlMode: true }), languages, relativePath, sitemapPath);
306
314
 
307
315
  // Save output
308
- jetpack.write(outPath, await formatDocument($.html(), undefined, false));
316
+ // const formatted = await formatDocument($.html(), 'html');
317
+
318
+ // console.log('----relativePath', relativePath);
319
+ // console.log('----filePath', filePath);
320
+ // console.log('----outPath', outPath);
321
+ // console.log('----FORMATTED.ERROR', formatted.error);
322
+
323
+ // Write the translated file
324
+ // jetpack.write(outPath, formatted.content);
309
325
  // logger.log(`✅ Wrote: ${outPath}`);
310
326
 
311
327
  // Track updated files only if it's new or updated
@@ -334,13 +350,23 @@ async function processTranslation() {
334
350
  }
335
351
  }
336
352
 
353
+ // Log skipped files
354
+ logger.warn('🚫 Skipped files:');
355
+ let totalSkipped = 0;
356
+ for (const [lang, meta] of Object.entries(metas)) {
357
+ if (meta.skipped.size > 0) {
358
+ logger.warn(` [${lang}] ${meta.skipped.size} skipped files:`);
359
+ meta.skipped.forEach(f => logger.warn(` ${f}`));
360
+ totalSkipped += meta.skipped.size;
361
+ }
362
+ }
363
+ if (totalSkipped === 0) {
364
+ logger.warn(' NONE');
365
+ }
366
+
337
367
  // Save all updated meta files
338
368
  for (const lang of languages) {
339
369
  jetpack.write(metas[lang].path, metas[lang].meta);
340
- if (metas[lang].skipped.length) {
341
- logger.warn('🚫 Skipped files:');
342
- metas[lang].skipped.forEach(f => logger.warn(f));
343
- }
344
370
  }
345
371
 
346
372
  // Log total token usage
@@ -521,9 +547,14 @@ async function insertLanguageTags($, languages, relativePath, filePath) {
521
547
 
522
548
  // Save the modified HTML back to the file if filePath
523
549
  if (filePath) {
524
- // const format = isHtml ? 'html' : 'xml';
525
- const format = 'html';
526
- jetpack.write(filePath, await formatDocument($.html(), format));
550
+ const format = isHtml ? 'html' : 'xml';
551
+ const formatted = await formatDocument($.html(), format);
552
+
553
+ console.log('---SAVING filePath', filePath);
554
+ console.log('---SAVING formatted.error', formatted.error);
555
+
556
+ // Write the formatted content back to the file
557
+ jetpack.write(filePath, formatted.content);
527
558
  }
528
559
  }
529
560
 
@@ -6,10 +6,9 @@ const path = require('path');
6
6
  // Load package
7
7
  const rootPathPackage = Manager.getRootPath('main');
8
8
 
9
- module.exports = async function formatHTML(content, format, throwError) {
9
+ module.exports = async (content, format) => {
10
10
  // Set default format to 'html' if not provided
11
11
  format = format || 'html';
12
- throwError = typeof throwError === 'undefined' ? true : throwError;
13
12
 
14
13
  // Setup Prettier options
15
14
  const options = {
@@ -30,16 +29,19 @@ module.exports = async function formatHTML(content, format, throwError) {
30
29
  return prettier
31
30
  .format(content, options)
32
31
  .then((formatted) => {
33
- return removeMultipleNewlines(formatted);
32
+ return {
33
+ content: removeMultipleNewlines(formatted),
34
+ error: null,
35
+ };
34
36
  })
35
37
  .catch((e) => {
36
- if (throwError) {
37
- throw e;
38
- }
39
- return removeMultipleNewlines(content);
38
+ return {
39
+ content: removeMultipleNewlines(content),
40
+ error: e,
41
+ };
40
42
  });
41
43
  };
42
44
 
43
45
  function removeMultipleNewlines(content) {
44
- return content.replace(/\n\s*\n+/g, '\n');
46
+ return content.replace(/\n\s*\n+/g, '\n').trim();
45
47
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ultimate-jekyll-manager",
3
- "version": "0.0.38",
3
+ "version": "0.0.39",
4
4
  "description": "Ultimate Jekyll dependency manager",
5
5
  "main": "dist/index.js",
6
6
  "exports": {