高高的git子模块用于私人内容?
我正在尝试使用高度和Netlify来创建一个具有公共和私人内容的网站,后者需要进行身份验证,如 11ty/demo-eto noveless-auth-auth 样本项目。我希望公共和私人内容在单独的公共和私人GIT存储库中,以便任何人都可以为前者做出贡献而无需看到后者。
我通过为私有内容使用git子模块而变得非常接近,但是我很难保留- 观看
自动重建和浏览器功能。问题在于Input
目录,该目录需要两个存储库中的内容文件。
最初,我尝试在build
和start
命令中复制私有内容npm运行dev
,当内容更改时不会重新运行。
然后我找到 ever> ever> ever
ever event ,我希望将其与fs-extra.copysync
一起使用,将文件从私有存储库移动到我的input
目录中。
但是,问题是input
也正在观看,因此复制触发器另一个构建,因此是无限的循环。我有些东西我've探索:
input
在ever.epter.fer
事件的回调中删除目录但这似乎打破了整个网站。- 也许它会破坏网站,因为 noreless noreferrer“> serverless plunin 用作输入?为了解决该问题,我尝试使用a second,未匹配的内容的副本指定插件的不同
inputDir
,但它无济于事。 - 或者可能会破坏网站,因为
fs-extra.rmsync
也会触发重建,但现在没有内容。
- 也许它会破坏网站,因为 noreless noreferrer“> serverless plunin 用作输入?为了解决该问题,我尝试使用a second,未匹配的内容的副本指定插件的不同
- 我想尝试一个同步的,而不是
ynnc
方法 expenty.before 处理程序,以防万一竞赛条件触发了无限循环。我尝试了everconfig.setWatchThrottLottleWaittime
来模拟这一点,但这无济于事,也许是因为该选项现在不支持。 - 我可以将
输入
目录作为手表目标删除,只查看我的两个预合并内容目录...但是该功能似乎不存在。 - 我尝试将组合的
输入
目录添加到.eleventyignore
inepipenty中:
之后,并在中删除目的是使其仅在构建过程中可见,否则无法触发变化,但这也无效。
我正在与之合作的仓库IS 在这里。我缺少什么,还是需要完全不同的方法?
I'm trying to use Eleventy and Netlify to create a website with both public and private content, with the latter requiring authentication as in the 11ty/demo-eleventy-serverless-auth sample project. I'd like the public and private content to be in separate public and private git repositories, so that anyone can contribute to the former without being able to see the latter.
I've gotten quite close by using a git submodule for the private content, but I'm having trouble preserving the --watch
automatic rebuilding and Browsersync functionality. The problem is with the input
directory, which needs the content files from both repositories.
Initially I tried to copy the private content prior to the build
and start
commands in package.json
, but that only gets run once at the beginning of npm run dev
, and does not get re-run when the content changes.
Then I found the eleventy.before
event, which I hoped to use with fs-extra.copySync
to move the files from the private repo into my input
directory.
The problem, however, is that the input
is also being watched, so the copy triggers another build and thus an infinite loop. Some things I've explored:
- Deleting the
input
directory in the callback for theeleventy.after
event, which I hoped would be safe sinceoutput
exists already, but this seems to break the entire site.- Maybe it breaks the site because the Serverless plugin no longer has files to use as input? To fix that I tried to specify a different
inputDir
for the plugin with a second, unwatched copy of the content, but that it didn't help. - Or maybe it breaks the site because the
fs-extra.rmSync
also triggers a rebuild, but now there's no content.
- Maybe it breaks the site because the Serverless plugin no longer has files to use as input? To fix that I tried to specify a different
- I wanted to try a synchronous, rather than
async
method in theeleventy.before
handler, in case there was a race condition triggering the infinite loop. I experimented witheleventyConfig.setWatchThrottleWaitTime
to simulate this, but it didn't help, perhaps because that option is now unsupported. - I could remove the
input
directory as a watch target and only look at my two pre-merge content directories... but that functionality doesn't seem to exist. - I tried adding the combined
input
directory to.eleventyignore
ineleventy:after
and removing it ineleventy:before
, with the goal to make it only visible during the build and otherwise not able to trigger changes, but that didn't work either.
The repo I'm working with is here. Is there something I'm missing, or do I need an entirely different approach?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
感谢 11ty Discord ,我通过保留未更换文件的修改时间来解决此问题。
在
ever.before
事件处理程序中,我使用了创建我需要复制的所有文件的列表。然后,对于每条路径,在用
fs.existsync
确认源和目标之后,我使用fs.statsync
比较了他们的mtimems
上次修改时间。然后,如果目标比源老(或丢失),则仅执行fs.copysync
。这解决了无限循环,但仅揭示了仅在Netlify上出现的另一个问题:我的动态页面的无服务器功能只有我项目文件的一个子集。首先,它缺少私有内容目录,在我的
expecter中触发错误。幸运的是, did 具有合并的内容目录,并且已经包含了我以前构建中的私人内容。但是,合并的内容目录并未从公共内容目录中具有
_的
文件夹,这导致无服务器函数在渲染模板时失败。因此,我不是在构建时间创建合并的内容目录,而是从公共和私人内容目录中复制所有内容,而是从一开始就保留
_includes
目录。这意味着ipery.before
事件处理程序仅复制.md
文件。这避免了第二个问题,无论如何,如果我以后我想将公共内容也将其移至单独的存储库,则可能会更好。Thanks to a suggestion from Aankhen#6432 in the 11ty Discord, I solved this by preserving the modification times of unchanged files.
In the
eleventy.before
event handler I usedklaw-sync
to create a list of all of the files I needed to copy. Then for each path, after confirming the source and destination withfs.existsSync
, I usedfs.statSync
to compare theirmtimeMs
last modification times. I then only perform thefs.copySync
if the destination is older than the source (or is missing).This resolved the infinite loop, but revealed another issue present only on Netlify: the serverless function for my dynamic pages had just a subset of my project's files. First, it was missing the private content directory, triggering an error in my
eleventy.before
handler when there was nothing to copy. Fortunately, it did have the merged content directory, and that already contained my private content from a previous build. The merged content directory did not, however, have the_includes
folder from the public content directory, which caused the serverless function to fail when rendering the templates.So, rather than create the merged content directory at build time and copy in everything from the public and private content directories, I just kept the
_includes
directory there from the beginning. That means theeleventy.before
event handler is only copying.md
files. This avoids this second problem and is maybe better anyway, in case I later want to move the public content into a separate repo as well.