Skip to content

Commit

Permalink
fix(core): change api "older" rules
Browse files Browse the repository at this point in the history
  • Loading branch information
zoobestik committed Nov 27, 2024
1 parent aefcb4b commit 462644a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 4 additions & 3 deletions scripts/doindex/analyzer/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { env } from 'node:process';
import { mkdir } from 'node:fs/promises';
import { EventEmitter } from 'events'
import { EventEmitter } from 'events';

import { DIST_FOLDER, REPORT_FOLDER } from '../lib/files/index.js';
import { execFilesTask, Filter } from '../lib/files/execTask.js';
import { writeReports } from './reports/write.js';
import { Metadata } from './metadata.js';
import { isApiPreviousVersion } from '../lib/files/type.js';

console.time('Data successfully built');

Expand All @@ -14,7 +15,7 @@ const TASK_PATH = import.meta.dirname + '/task';
function preFilterFiles({ relativePath: path }: Parameters<Filter>[0]) {
const isSkip = (
// optimize by path "api/core/older" takes more than 1 minute only for filesystem iteration
(path.startsWith('api/') && (path.endsWith('/older'))) ||
isApiPreviousVersion(path) ||
path === 'spec' ||
path === 'api/latest'
);
Expand All @@ -25,7 +26,7 @@ function preFilterFiles({ relativePath: path }: Parameters<Filter>[0]) {

let result: Metadata[] = [];

EventEmitter.defaultMaxListeners = 15
EventEmitter.defaultMaxListeners = 15;

await execFilesTask(
DIST_FOLDER, TASK_PATH,
Expand Down
6 changes: 5 additions & 1 deletion scripts/doindex/lib/files/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export type FileType =
| 'Page_Community' | 'Page_Documentation' | 'Page_LegacyDocumentation'
| 'Iframe' | 'Redirect' | 'Hidden' | 'Unknown';

export function isApiPreviousVersion(url: string) {
return url.match(/^api\/[^/]+\/(\d+\.\d+(\.\d+)?)\//)?.[1];
}

export async function getType(url: string, filePath: string): Promise<[FileType, CheerioAPI | null]> {
if (url.endsWith('/package-list') || url.endsWith('index.yml')) return ['File_Text', null];
if (url.endsWith('.pdf')) return ['File_Pdf', null];
Expand Down Expand Up @@ -47,7 +51,7 @@ export async function getType(url: string, filePath: string): Promise<[FileType,
if (url.startsWith('api/latest/')) pageType = url.includes('jvm/stdlib') ? 'Page_API_stdlib' : 'Page_API_test';
else if (url.endsWith('/navigation.html') && $(':is(.sideMenu, .sideMenuPart) .sideMenuPart').length)
pageType = 'Iframe';
else if (url.includes('/older/')) return ['Page_API_Deprecated', $];
else if (isApiPreviousVersion(url)) return ['Page_API_Deprecated', $];
else pageType = 'Page_API';
}

Expand Down

0 comments on commit 462644a

Please sign in to comment.