Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 26x 24x 22x 22x 21x 21x 1x 3x 3x 12x 12x 12x 12x 8x 8x 7x 7x 4x 4x 2x 2x 1x 1x 2x 2x 2x 21x 21x 24x 21x 24x 24x 24x 24x 8x 8x 8x 8x 21x 21x 24x 24x 24x 23x 21x 24x 21x 21x 23x 23x 1x 21x 21x 21x 21x 21x 20x 4x 4x 26x | #!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const parseReadme = require('./parseReadme');
const fetchGithub = require('./fetchGithub');
const mediaDownloader = require('./media/mediaDownloader');
const translation = require('./translation');
const { shouldTranslateUI, translateWithCache } = translation;
const { getAxios } = require('./axiosLoader');
const TOKEN = process.env.GH_PROJECTS_TOKEN || process.env.GITHUB_TOKEN;
const DEBUG_FETCH = process.env.DEBUG_FETCH === '1' || process.env.DEBUG_FETCH === 'true';
const OUT_PATH = path.join(__dirname, '..', '..', 'public', 'projects.json');
const MEDIA_ROOT = path.join(__dirname, '..', '..', 'public', 'projects_media');
const QUERY = `query getPinned($login: String!) { user(login: $login) { pinnedItems(first: 12, types: [REPOSITORY]) { nodes { __typename ... on Repository { name description url } } } } }`;
async function fetchGraphQL() {
if (!TOKEN) {
// No token in this environment; fall back to the existing projects.json for local dev
try {
const raw = fs.readFileSync(OUT_PATH, 'utf8');
const nodes = JSON.parse(raw);
if (Array.isArray(nodes)) return nodes;
} catch (e) {
throw new Error('No GH token set and failed to read existing public/projects.json; provide GH_PROJECTS_TOKEN or create public/projects.json');
}
}
Iif (!fetchGithub || !fetchGithub.runGraphQL) throw new Error('fetchGithub.runGraphQL not available');
return fetchGithub.runGraphQL(TOKEN, QUERY, { login: 'keglev' });
}
function convertToGhPages(link, repoName) {
Iif (!link || !repoName) return null;
const s = String(link).trim();
const raw = s.match(/^https?:\/\/raw\.githubusercontent\.com\/keglev\/([^/]+)\/(?:main|master)\/(.+)$/i);
if (raw && raw[1] && raw[2]) {
const urlPath = raw[2].replace(/^\/*/, '');
if (/\.md$/i.test(urlPath)) return null;
Eif (/\bdocs\b/i.test(urlPath) || /api\.(?:md|html)$/i.test(urlPath) || /\bapi\b/i.test(urlPath)) {
return `https://keglev.github.io/${raw[1]}/${urlPath}`;
}
}
const blob = s.match(/^https?:\/\/github\.com\/keglev\/([^/]+)\/blob\/(?:main|master)\/(.+)$/i);
if (blob && blob[1] && blob[2]) {
const urlPath = blob[2].replace(/^\/*/, '');
if (/\.md$/i.test(urlPath)) return null;
Eif (/\bdocs\b/i.test(urlPath) || /api\.(?:md|html)$/i.test(urlPath) || /\bapi\b/i.test(urlPath)) {
return `https://keglev.github.io/${blob[1]}/${urlPath}`;
}
}
const rel = s.match(/(?:src\/(?:main\/)?docs|docs)\/(.+\.(?:md|html))/i);
Iif (rel && rel[1]) return `https://keglev.github.io/${repoName}/${rel[0].replace(/^\/*/, '')}`;
return null;
}
async function applyGithubIoPreferences(nodes) {
const { applyGithubIoToNode } = require('./normalize/githubIoPreferer');
for (const node of nodes) {
try { await applyGithubIoToNode(node, getAxios, DEBUG_FETCH); } catch (e) { if (DEBUG_FETCH) console.log('applyGithubIoPreferences failed for', node.name, e && e.message); }
}
}
function applyGhPagesConversion(nodes) {
for (const node of nodes) {
try {
Iif (!node) continue;
if (node.docsLink) { const c = convertToGhPages(node.docsLink, node.name); if (c) node.docsLink = c; }
if (node.repoDocs) {
const rd = node.repoDocs;
if (rd.apiDocumentation && rd.apiDocumentation.link) { const c = convertToGhPages(rd.apiDocumentation.link, node.name); if (c) rd.apiDocumentation.link = c; }
if (rd.architectureOverview && rd.architectureOverview.link) { const c = convertToGhPages(rd.architectureOverview.link, node.name); Eif (c) rd.architectureOverview.link = c; }
if (rd.testing && rd.testing.testingDocs && rd.testing.testingDocs.link) { const c = convertToGhPages(rd.testing.testingDocs.link, node.name); Eif (c) rd.testing.testingDocs.link = c; }
}
} catch (e) { if (DEBUG_FETCH) console.log('applyGhPagesConversion failed for', node.name, e && e.message); }
}
}
function runNormalizationPass(nodes) {
const { normalizeRepoDocsLinks } = require('./normalize/normalize');
for (const node of nodes) {
try { normalizeRepoDocsLinks(node); } catch (e) { if (DEBUG_FETCH) console.log('normalize failed for', node.name, e && e.message); }
}
}
/**
* Fetches pinned repositories from GitHub, runs the full per-node processing pipeline
* (README parsing, doc extraction, translation, media download), then writes projects.json.
* Filters GraphQL results to Repository nodes only — gists and other pinnedItem types are excluded.
*
* @returns {Promise<void>}
*/
async function fetchPinned() {
try {
const nodes = await fetchGraphQL();
if (!Array.isArray(nodes)) throw new Error('Invalid response from GraphQL');
mediaDownloader.ensureDir(MEDIA_ROOT);
// Filter to Repository items; pinnedItems may also contain Gists
const repoNodes = nodes.filter(n => n && n.__typename === 'Repository');
const nodeProcessor = require('./pipeline/nodeProcessor');
for (const node of repoNodes) {
try {
await nodeProcessor.processNode(node, { getAxios, MEDIA_ROOT, parseReadme, translateWithCache, shouldTranslateUI, DEBUG_FETCH });
} catch (e) { Iif (DEBUG_FETCH) console.log('nodeProcessor failed for', node.name, e && e.message); }
}
runNormalizationPass(nodes);
await applyGithubIoPreferences(nodes);
applyGhPagesConversion(nodes);
const writer = require('./output/writeProjects');
writer.writeProjectsJson(OUT_PATH, nodes);
console.log('Wrote', OUT_PATH);
} catch (err) {
console.error('Failed to fetch pinned repositories:', (err && err.message) || err);
process.exit(3);
}
}
module.exports = { fetchPinned };
|