Change the clone part to a before, instead of after, hook

3820b5156f4ff5313be541b5b0e1192d252bee54

Tucker McKnight <tucker@pangolin.lan> | Sun Jan 11 2026

Change the clone part to a before, instead of after, hook

The buildSteps part still needs to happen in an after hook (throws an
error about the repository not existing otherwise), but we can clone
the repo and put it in the _site directory before the site generation
happens.

This also seems to fix a race condition that was happening with buildSteps,
which was sometimes throwing an error about the repo not existing when
it was trying to do the build steps. I'm assuming that's because somehow
the buildSteps were running before the repo was done cloning.

A side effect of this is that the repo can be cloned and available in your
public HTML folder even if the site generation fails. So people can be
pulling commits from the repo that are not mentioned in the HTML pages.

This might actually be a good thing -- users might want their code to be
available, even if the site isn't up-to-date.
main.ts:63
Before
62
63
64
65
66
67
  })

  eleventyConfig.on(
    "eleventy.after",
    async ({ directories }) => {
      const cwd = process.cwd()
      // Check to see if there is already a repo in all of the locations
After
62
63
64
65
66
67
  })

  eleventyConfig.on(
    "eleventy.before",
    async ({ directories }) => {
      const cwd = process.cwd()
      // Check to see if there is already a repo in all of the locations
main.ts:87
Before
86
87
88













89
90
          await exec(`git clone ${originalLocation} ${eleventyConfig.dir.output + reposPath + "/" + gitRepoName} --bare`)
          await exec(`git -C ${eleventyConfig.dir.output + reposPath + "/" + gitRepoName} update-server-info`)
        }
⁣
⁣
⁣
⁣
⁣
⁣
⁣
⁣
⁣
⁣
⁣
⁣
⁣
        if (typeof repoConfig.buildSteps !== 'undefined') {
          // make a temp directory for things to run in
          const tempDirName = `temp_${Math.floor(Math.random() * 10000).toString()}`
After
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
          await exec(`git clone ${originalLocation} ${eleventyConfig.dir.output + reposPath + "/" + gitRepoName} --bare`)
          await exec(`git -C ${eleventyConfig.dir.output + reposPath + "/" + gitRepoName} update-server-info`)
        }

        const location = eleventyConfig.dir.output + reposPath + "/" + gitRepoName
        await exec(`git -C ${location} symbolic-ref HEAD refs/heads/${repoConfig.defaultBranch}`)
      }
    }
  )

  eleventyConfig.on(
    "eleventy.after",
    async ({ directories }) => {
      for (let repoName in reposConfiguration.repos) {
        const repoConfig = reposConfiguration.repos[repoName]

        if (typeof repoConfig.buildSteps !== 'undefined') {
          // make a temp directory for things to run in
          const tempDirName = `temp_${Math.floor(Math.random() * 10000).toString()}`
main.ts:106
Before
105
106
107
108
109
110
111
112
113
114
115
          // delete the temp dirs
          await exec(`rm -r ${tempDir}`)
        }

        const location = eleventyConfig.dir.output + reposPath + "/" + gitRepoName
        await exec(`git -C ${location} symbolic-ref HEAD refs/heads/${repoConfig.defaultBranch}`)
      }
    }
  );

  eleventyConfig.addFilter("getDirectoryContents", (repo: string, branch: string, dirPath: string) => {
    return reposData.find(current => current.name === repo).branches.find(current => current.name === branch).fileList.filter(file => file.startsWith(dirPath) && file !== dirPath)
After
105
106
107



108
109
110
111
112
          // delete the temp dirs
          await exec(`rm -r ${tempDir}`)
        }
⁣
⁣
⁣
      }
    }
  )

  eleventyConfig.addFilter("getDirectoryContents", (repo: string, branch: string, dirPath: string) => {
    return reposData.find(current => current.name === repo).branches.find(current => current.name === branch).fileList.filter(file => file.startsWith(dirPath) && file !== dirPath)
wiki/projects/clone-early.md:6
Before
5
6






> the site. This is also the point where it can figure out which
> branches match the user's provided branch glob names. (See
⁣
⁣
⁣
⁣
⁣
⁣
⁣
> [branch globs project](./branch-globs.md.html).)
After
5
6
7
8
9
10
11
12
13
> the site. This is also the point where it can figure out which
> branches match the user's provided branch glob names. (See
> [branch globs project](./branch-globs.md.html).)


## Brainstorming Jan 10, 2026

- Where to do this?
  - Currently, repo is clone in `main.ts` in an `eleventyConfig.on("eleventy.after")` callback
  - There is also an `eleventyConfig.on("eleventy.before")` that you can use