Something went wrong. Try again.
move github sites
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247// Classify what a repo's file tree says about how its site is produced.//// The question that matters for a Tangled migration is narrow: are there static// files sitting in the repo that can be served as-is, or does something have to// run first? Tangled serves files from a branch+directory with no build step, so// "needs a build" is the dividing line.
// Each entry: a generator, the files that identify it, and where it conventionally// writes output. outDir is a hint for finding an already-committed build.const GENERATORS = [ { id: 'jekyll', label: 'Jekyll', files: ['_config.yml', '_config.yaml'], outDir: '_site' }, { id: 'hugo', label: 'Hugo', files: ['hugo.toml', 'hugo.yaml', 'hugo.json', 'config.toml'], outDir: 'public' }, { id: 'eleventy', label: 'Eleventy', files: ['.eleventy.js', 'eleventy.config.js', 'eleventy.config.mjs', '.eleventy.cjs'], outDir: '_site' }, { id: 'astro', label: 'Astro', files: ['astro.config.mjs', 'astro.config.js', 'astro.config.ts'], outDir: 'dist' }, { id: 'next', label: 'Next.js', files: ['next.config.js', 'next.config.mjs', 'next.config.ts'], outDir: 'out' }, { id: 'docusaurus', label: 'Docusaurus', files: ['docusaurus.config.js', 'docusaurus.config.ts'], outDir: 'build' }, { id: 'gatsby', label: 'Gatsby', files: ['gatsby-config.js', 'gatsby-config.ts'], outDir: 'public' }, { id: 'mkdocs', label: 'MkDocs', files: ['mkdocs.yml', 'mkdocs.yaml'], outDir: 'site' }, { id: 'mdbook', label: 'mdBook', files: ['book.toml'], outDir: 'book' }, { id: 'vitepress', label: 'VitePress', files: ['.vitepress/config.js', '.vitepress/config.ts', 'docs/.vitepress/config.js', 'docs/.vitepress/config.ts'], outDir: 'docs/.vitepress/dist' }, { id: 'vite', label: 'Vite', files: ['vite.config.js', 'vite.config.ts', 'vite.config.mjs'], outDir: 'dist' }, { id: 'webpack', label: 'webpack', files: ['webpack.config.js'], outDir: 'dist' },]
// Deploy config for hosts other than GitHub Pages. Presence means the repo may// have a second live site we'd otherwise miss.const OTHER_HOSTS = [ { id: 'netlify', label: 'Netlify', files: ['netlify.toml'] }, { id: 'vercel', label: 'Vercel', files: ['vercel.json', '.vercel/project.json'] }, { id: 'cloudflare-pages', label: 'Cloudflare Pages', files: ['wrangler.toml', 'wrangler.jsonc', 'wrangler.json'] }, { id: 'firebase', label: 'Firebase Hosting', files: ['firebase.json'] }, { id: 'surge', label: 'Surge', files: ['CNAME.surge'] }, { id: 'render', label: 'Render', files: ['render.yaml'] },]
// Workflow actions that publish to Pages. Distinguishes "Actions builds and// deploys" from "Pages serves a branch directly".const PAGES_ACTIONS = [ 'actions/deploy-pages', 'actions/upload-pages-artifact', 'peaceiris/actions-gh-pages', 'JamesIves/github-pages-deploy-action', 'crazy-max/ghaction-github-pages', 'withastro/action',]
// Top-level directory names that conventionally hold a publishable site, used to// tell a real site root from an examples folder when the source path has no index.const PUBLISH_DIRS = new Set([ 'public', 'docs', 'dist', 'build', 'out', 'site', '_site', 'www', 'web', 'html', 'book', ...GENERATORS.map((g) => g.outDir).filter((d) => d && !d.includes('/')),])
const norm = (p) => p.replace(/^\/+|\/+$/g, '')
/** * @param {string[]} paths every blob path in the tree * @param {string} srcPath the Pages source directory ("/" or "/docs") */export function detect(paths, srcPath = '/') { const set = new Set(paths) const dir = norm(srcPath) const inDir = (f) => (dir ? `${dir}/${f}` : f)
const generators = GENERATORS.filter((g) => g.files.some((f) => set.has(f) || set.has(inDir(f)))).map( (g) => ({ id: g.id, label: g.label, outDir: g.outDir }) )
const otherHosts = OTHER_HOSTS.filter((h) => h.files.some((f) => set.has(f))).map((h) => ({ id: h.id, label: h.label, }))
// Static-ready means: an index.html actually lives at the directory Pages // serves from. That is exactly what Tangled needs, so it is the pass/fail bit. const indexAtSource = set.has(inDir('index.html'))
// Every directory holding an index.html, shallowest first. const indexDirs = paths .filter((p) => p === 'index.html' || p.endsWith('/index.html')) .map((p) => (p.includes('/') ? '/' + p.slice(0, -'/index.html'.length) : '/')) .filter((v, i, a) => a.indexOf(v) === i) .sort((a, b) => a.split('/').length - b.split('/').length || a.localeCompare(b))
// Of those, the ones plausibly holding the site itself rather than a demo or // fixture: a top-level directory with a conventional output name. Guessing // deeper than that turns example pages into "the homepage", which is worse // than admitting we could not find one. const plausibleDirs = indexDirs.filter((d) => PUBLISH_DIRS.has(d.slice(1)))
// A generator whose output directory is committed can be pointed at directly. const committedOutput = generators .map((g) => g.outDir) .filter((d) => d && set.has(`${d}/index.html`))
const hasCname = set.has('CNAME') || set.has(inDir('CNAME')) const hasNojekyll = set.has('.nojekyll') || set.has(inDir('.nojekyll'))
// GitHub Pages runs Jekyll unless told not to, so a bare README.md or index.md // at the source path is silently rendered into the homepage. Tangled serves // files verbatim, so these sites have no index at all once they move. const markdownIndex = !indexAtSource && !hasNojekyll && ['index.md', 'index.markdown', 'README.md', 'readme.md'].find((f) => set.has(inDir(f)))
// Layout and include directories mean Jekyll templating is in use even with no // _config.yml, so an index.html beside them may be a template, not a page. const jekyllTemplates = paths.some( (p) => p.startsWith(inDir('_layouts/')) || p.startsWith(inDir('_includes/')) )
const workflows = paths.filter((p) => /^\.github\/workflows\/.+\.ya?ml$/.test(p))
return { jekyllTemplates, generators, otherHosts, indexAtSource, indexDirs, plausibleDirs, committedOutput, markdownIndex: markdownIndex || null, hasCname, hasNojekyll, workflows, fileCount: paths.length, htmlCount: paths.filter((p) => p.endsWith('.html')).length, }}
/** Which Pages-publishing actions appear in the given workflow file contents. */export function detectPagesActions(workflowContents) { const hits = new Set() for (const text of workflowContents) { if (!text) continue for (const a of PAGES_ACTIONS) if (text.includes(a)) hits.add(a) } return [...hits]}
/** * Decide how a site would move to Tangled, and where Tangled should point. * * Tangled serves a branch + directory verbatim with no build, so the verdict * turns on three things: whether servable HTML exists somewhere in the tree, * whether the site depends on a custom domain, and whether it is still alive. */export function verdict(site) { const d = site.detect ?? {} const blockers = [] const notes = []
// An unreadable tree is not an empty one. A rate-limited or failed tree fetch // reports no paths, which would otherwise read as "nothing servable". if (d.treeError) { return { effort: 'unknown', deploy: null, blockers: [`could not read the file tree (GitHub answered ${d.treeError}) — rescan`], notes, } }
// Whether something transforms the tree before GitHub serves it. When it does, // an index.html in the source is likely a build entry or a template (Vite's // index.html, a Jekyll page with front matter), and serving it verbatim would // publish source. Jekyll only counts when it actually runs: .nojekyll turns it // off, and plain HTML with no config or templates passes through unchanged. const jekyllRuns = !d.hasNojekyll && (d.jekyllTemplates || d.generators?.some((g) => g.id === 'jekyll')) const builders = [ ...(d.generators ?? []).filter((g) => g.id !== 'jekyll').map((g) => g.label), ...(jekyllRuns ? ['Jekyll'] : []), ...(site.buildType === 'workflow' ? ['a GitHub Actions workflow'] : []), ]
// Where Tangled would deploy from, if anywhere. let deploy = null if (d.committedOutput?.length) { deploy = { branch: site.branch, dir: '/' + d.committedOutput[0] } notes.push(`built output committed at ${d.committedOutput[0]}`) } else if (d.indexAtSource && !builders.length) { deploy = { branch: site.branch, dir: site.sourcePath || '/' } notes.push('index.html already at the Pages source path') } else if (d.indexAtSource) { blockers.push( `index.html at the source path is input to ${builders.join(' and ')}, not the served page — needs a build step` ) } else if (d.plausibleDirs?.length && !builders.length) { deploy = { branch: site.branch, dir: d.plausibleDirs[0] } notes.push(`no index at the source path; site looks like it lives in ${d.plausibleDirs[0]}`) }
if (!deploy && !blockers.length) { if (d.markdownIndex) { blockers.push( `homepage is ${d.markdownIndex} rendered by GitHub's implicit Jekyll build — Tangled serves files verbatim, so there would be no index` ) } else if (d.generators?.length) { blockers.push( `built by ${d.generators.map((g) => g.label).join('/')} with no committed output — needs a build step` ) } else if (site.buildType === 'workflow') { blockers.push('published by a GitHub Actions workflow — output never lands in the repo') } else if (d.indexDirs?.length) { blockers.push( `no index.html at the source path; the only ones found are under ${d.indexDirs.slice(0, 3).join(', ')}, which look like examples rather than the site` ) } else { blockers.push('no index.html anywhere in the tree') } }
if (site.customDomain) { blockers.push(`custom domain ${site.customDomain} — Tangled has no custom-domain support yet`) }
const reachable = site.live?.ok === true if (site.live && !reachable) { notes.push(`not reachable today (${site.live.error ? 'request failed' : site.live.status})`) }
// A truncated tree still proves what it contains, but not what it lacks. if (d.truncated) notes.push('GitHub truncated the file tree; files beyond the cut were not seen')
let effort if (!site.pages && d.otherHosts?.length) effort = 'elsewhere' else if (!deploy && !reachable && d.truncated) effort = 'unknown' else if (!deploy && !reachable) effort = 'dead' else if (!deploy) effort = 'needs-build' else if (site.customDomain) effort = 'domain-decision' else effort = 'automatic'
return { effort, deploy, blockers, notes }}