openprototype 1.8.1 → 1.8.2
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.
package/package.json
CHANGED
|
@@ -756,29 +756,31 @@ function loadVersionCache() { try { return JSON.parse(navStorage.getItem(VER_CAC
|
|
|
756
756
|
function saveVersionCache() { navStorage.setItem(VER_CACHE_KEY, JSON.stringify(versionCache)); }
|
|
757
757
|
versionCache = loadVersionCache();
|
|
758
758
|
|
|
759
|
-
function
|
|
760
|
-
const
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
for (let index = 0; index < length; index += 1) {
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
const
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
759
|
+
function extractPrdHistoryLatestVersion(text) {
|
|
760
|
+
const lines = String(text || '').replace(/<[^>]+>/g, '').split(/\r?\n/);
|
|
761
|
+
let latestVersion = null;
|
|
762
|
+
|
|
763
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
764
|
+
if (!/^\s*\|.*\|\s*$/.test(lines[index])) continue;
|
|
765
|
+
|
|
766
|
+
const tableLines = [];
|
|
767
|
+
while (index < lines.length && /^\s*\|.*\|\s*$/.test(lines[index])) {
|
|
768
|
+
tableLines.push(lines[index]);
|
|
769
|
+
index += 1;
|
|
770
|
+
}
|
|
771
|
+
index -= 1;
|
|
772
|
+
|
|
773
|
+
if (tableLines.length < 3 || !/^\s*\|(?:\s*:?-{3,}:?\s*\|)+\s*$/.test(tableLines[1])) continue;
|
|
774
|
+
const headerCell = tableLines[0].split('|')[1] || '';
|
|
775
|
+
if (!headerCell.includes('版本')) continue;
|
|
776
|
+
|
|
777
|
+
tableLines.slice(2).forEach(row => {
|
|
778
|
+
const version = (row.split('|')[1] || '').trim();
|
|
779
|
+
if (version) latestVersion = version;
|
|
780
|
+
});
|
|
772
781
|
}
|
|
773
|
-
return 0;
|
|
774
|
-
}
|
|
775
782
|
|
|
776
|
-
|
|
777
|
-
const plainText = String(text || '').replace(/<[^>]+>/g, '');
|
|
778
|
-
const versions = [...plainText.matchAll(/^\|\s*(v\d+(?:\.[0-9a-z]+)+)\s*\|/gim)].map(match => match[1]);
|
|
779
|
-
return versions.length
|
|
780
|
-
? versions.reduce((maxVersion, version) => comparePrdVersions(version, maxVersion) > 0 ? version : maxVersion)
|
|
781
|
-
: null;
|
|
783
|
+
return latestVersion;
|
|
782
784
|
}
|
|
783
785
|
|
|
784
786
|
async function fetchPageVersion(htmlPath) {
|
|
@@ -787,7 +789,7 @@ async function fetchPageVersion(htmlPath) {
|
|
|
787
789
|
const res = await fetch(mdPath, { cache: 'no-cache' });
|
|
788
790
|
if (!res.ok) return null;
|
|
789
791
|
const text = await res.text();
|
|
790
|
-
return
|
|
792
|
+
return extractPrdHistoryLatestVersion(text);
|
|
791
793
|
} catch { return null; }
|
|
792
794
|
}
|
|
793
795
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
// 页面可在引入本模块前声明这些全局以覆盖默认行为;未声明时使用默认值。
|
|
7
|
-
// “当前版本”优先读取主 PRD
|
|
7
|
+
// “当前版本”优先读取主 PRD 版本记录表的最后一条;PRD_OVERVIEW_VERSION 仅作兼容兜底。
|
|
8
8
|
// PRD_WORKSPACE_MAP 配置多文档工作区。
|
|
9
9
|
var PRD_BASE_PATH = typeof PRD_BASE_PATH !== 'undefined' ? PRD_BASE_PATH : './';
|
|
10
10
|
var PRD_FILE_MAP = typeof PRD_FILE_MAP !== 'undefined' ? PRD_FILE_MAP : {};
|
|
@@ -434,41 +434,36 @@ function getPrdDisplayName(filePath) {
|
|
|
434
434
|
return (filePath || '').split('/').pop().replace(/\.md(?:#.*)?$/i, '').replace(/_/g, ' ');
|
|
435
435
|
}
|
|
436
436
|
|
|
437
|
-
function
|
|
438
|
-
var
|
|
439
|
-
var
|
|
440
|
-
var length = Math.max(leftParts.length, rightParts.length);
|
|
441
|
-
|
|
442
|
-
for (var index = 0; index < length; index += 1) {
|
|
443
|
-
var leftPart = leftParts[index] || '0';
|
|
444
|
-
var rightPart = rightParts[index] || '0';
|
|
445
|
-
var leftNumber = /^\d+$/.test(leftPart) ? Number(leftPart) : null;
|
|
446
|
-
var rightNumber = /^\d+$/.test(rightPart) ? Number(rightPart) : null;
|
|
447
|
-
var comparison = leftNumber !== null && rightNumber !== null
|
|
448
|
-
? leftNumber - rightNumber
|
|
449
|
-
: leftPart.localeCompare(rightPart, undefined, { numeric: true, sensitivity: 'base' });
|
|
450
|
-
if (comparison !== 0) return comparison;
|
|
451
|
-
}
|
|
452
|
-
return 0;
|
|
453
|
-
}
|
|
437
|
+
function getPrdHistoryLatestVersion(content) {
|
|
438
|
+
var lines = String(content || '').replace(/<[^>]+>/g, '').split(/\r?\n/);
|
|
439
|
+
var latestVersion = '';
|
|
454
440
|
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
441
|
+
for (var index = 0; index < lines.length; index += 1) {
|
|
442
|
+
if (!/^\s*\|.*\|\s*$/.test(lines[index])) continue;
|
|
443
|
+
|
|
444
|
+
var tableLines = [];
|
|
445
|
+
while (index < lines.length && /^\s*\|.*\|\s*$/.test(lines[index])) {
|
|
446
|
+
tableLines.push(lines[index]);
|
|
447
|
+
index += 1;
|
|
448
|
+
}
|
|
449
|
+
index -= 1;
|
|
450
|
+
|
|
451
|
+
if (tableLines.length < 3 || !/^\s*\|(?:\s*:?-{3,}:?\s*\|)+\s*$/.test(tableLines[1])) continue;
|
|
452
|
+
var headerCell = tableLines[0].split('|')[1] || '';
|
|
453
|
+
if (headerCell.indexOf('版本') === -1) continue;
|
|
454
|
+
|
|
455
|
+
tableLines.slice(2).forEach(function(row) {
|
|
456
|
+
var version = (row.split('|')[1] || '').trim();
|
|
457
|
+
if (version) latestVersion = version;
|
|
458
|
+
});
|
|
462
459
|
}
|
|
463
|
-
|
|
464
|
-
return
|
|
465
|
-
return comparePrdVersions(version, maxVersion) > 0 ? version : maxVersion;
|
|
466
|
-
});
|
|
460
|
+
|
|
461
|
+
return latestVersion;
|
|
467
462
|
}
|
|
468
463
|
|
|
469
464
|
function getPrdOverviewVersion(rootContent) {
|
|
470
|
-
var
|
|
471
|
-
if (
|
|
465
|
+
var historyLatestVersion = getPrdHistoryLatestVersion(rootContent);
|
|
466
|
+
if (historyLatestVersion) return historyLatestVersion;
|
|
472
467
|
if (prdOverviewVersion) return prdOverviewVersion;
|
|
473
468
|
if (typeof PRD_OVERVIEW_VERSION === 'undefined') return '';
|
|
474
469
|
return String(PRD_OVERVIEW_VERSION || '').trim();
|
|
@@ -756,29 +756,31 @@ function loadVersionCache() { try { return JSON.parse(navStorage.getItem(VER_CAC
|
|
|
756
756
|
function saveVersionCache() { navStorage.setItem(VER_CACHE_KEY, JSON.stringify(versionCache)); }
|
|
757
757
|
versionCache = loadVersionCache();
|
|
758
758
|
|
|
759
|
-
function
|
|
760
|
-
const
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
for (let index = 0; index < length; index += 1) {
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
const
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
759
|
+
function extractPrdHistoryLatestVersion(text) {
|
|
760
|
+
const lines = String(text || '').replace(/<[^>]+>/g, '').split(/\r?\n/);
|
|
761
|
+
let latestVersion = null;
|
|
762
|
+
|
|
763
|
+
for (let index = 0; index < lines.length; index += 1) {
|
|
764
|
+
if (!/^\s*\|.*\|\s*$/.test(lines[index])) continue;
|
|
765
|
+
|
|
766
|
+
const tableLines = [];
|
|
767
|
+
while (index < lines.length && /^\s*\|.*\|\s*$/.test(lines[index])) {
|
|
768
|
+
tableLines.push(lines[index]);
|
|
769
|
+
index += 1;
|
|
770
|
+
}
|
|
771
|
+
index -= 1;
|
|
772
|
+
|
|
773
|
+
if (tableLines.length < 3 || !/^\s*\|(?:\s*:?-{3,}:?\s*\|)+\s*$/.test(tableLines[1])) continue;
|
|
774
|
+
const headerCell = tableLines[0].split('|')[1] || '';
|
|
775
|
+
if (!headerCell.includes('版本')) continue;
|
|
776
|
+
|
|
777
|
+
tableLines.slice(2).forEach(row => {
|
|
778
|
+
const version = (row.split('|')[1] || '').trim();
|
|
779
|
+
if (version) latestVersion = version;
|
|
780
|
+
});
|
|
772
781
|
}
|
|
773
|
-
return 0;
|
|
774
|
-
}
|
|
775
782
|
|
|
776
|
-
|
|
777
|
-
const plainText = String(text || '').replace(/<[^>]+>/g, '');
|
|
778
|
-
const versions = [...plainText.matchAll(/^\|\s*(v\d+(?:\.[0-9a-z]+)+)\s*\|/gim)].map(match => match[1]);
|
|
779
|
-
return versions.length
|
|
780
|
-
? versions.reduce((maxVersion, version) => comparePrdVersions(version, maxVersion) > 0 ? version : maxVersion)
|
|
781
|
-
: null;
|
|
783
|
+
return latestVersion;
|
|
782
784
|
}
|
|
783
785
|
|
|
784
786
|
async function fetchPageVersion(htmlPath) {
|
|
@@ -787,7 +789,7 @@ async function fetchPageVersion(htmlPath) {
|
|
|
787
789
|
const res = await fetch(mdPath, { cache: 'no-cache' });
|
|
788
790
|
if (!res.ok) return null;
|
|
789
791
|
const text = await res.text();
|
|
790
|
-
return
|
|
792
|
+
return extractPrdHistoryLatestVersion(text);
|
|
791
793
|
} catch { return null; }
|
|
792
794
|
}
|
|
793
795
|
|