Skip to content
This repository has been archived by the owner on Jul 17, 2022. It is now read-only.

静态文件支持 #1

Closed
wants to merge 4 commits into from
Closed

Conversation

cooker
Copy link

@cooker cooker commented Jan 12, 2022

测试流程
以potatoes 项目为例,在resources/static 新增需要的js、css、flt等静态资源。并build(打包)

  1. 将 potatoes-1.0-SNAPSHOT-plain.jar 放入plugins插件加载目录
  2. halo 主程序启动后,当PluginManagerController#start 接口被调用,会将jar里面的resources/static 所有资源复制到 ${user.home}/halo-dev/static/{pluginId} 目录下
  3. 访问 ${halo.plugin.controller.base-path:/plugins}/web/{pluginId}/ ,就能正常访问静态资源

本地调试

  1. core 主程序会加载工程目录 plugins/potatoes 下{pluginId}-*.jar ,将resources/static资源进行复制

@guqing
Copy link
Owner

guqing commented Jan 13, 2022

hi @cooker 感谢你对此提交PR,不过为了方便你应该在描述中说明该如何测试它

@guqing
Copy link
Owner

guqing commented Jan 21, 2022

@cooker 非常感谢你的贡献,不过我测试的过程中功能上还有些小问题,比如我访问http://localhost:8090/plugins/web/potatoes/abc/ 时 报错会提示 NOT FOUND potatoes/abc/.ftl 或许带/应该访问的是potatoes/abc/index.ftl


public class FileViewerTest {
public static void main(String[] args) throws IOException {
// String file = "F:\\IT\\Code\\halo-plugin-experimental\\build\\plugins\\plugin-potatoes-1.0-SNAPSHOT.zip";
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cooker 这个测试文件只能运行在windows机器上而无法运行在ci或我的linux 可以将绝对路径改为相对路径或通过Files创建临时目录来编写

//task zipStatic(type: Zip) {
// from 'src/main/resources/static/'
// include '*'
// include '*/*'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cooker 这些不需要的注释需要删一下

<div>
<p>Index abc</p>
</div>
</html>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cooker 行末需要一个空行

<div>
<p>Index</p>
</div>
</html>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cooker 同上

final PathMatcher pathMatcher = FileSystems.getDefault().getPathMatcher("glob:**/"+pluginId+"-*.jar");
try {
final Path[] sourcePath = {null};
Files.walkFileTree(path, new SimpleFileVisitor<Path>(){
Copy link
Owner

@guqing guqing Jan 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cooker 我认为没有必要去遍历目录 效率太低了 特别时目录很深时,在 deployment 模式下通过

Path path = event.getPlugin().getPluginPath().toAbsolutePath();

已经可以获取到目录。
而在 development 模式下加载插件时使用的是 build/classes的内容因此实际是没有使用jar包的但是这里的静态文件加载还是依赖jar并且还解压了,我认为在开发模式下应该区别对待 可以直接通过插件类加载器获取到静态文件的目录直接复制到 halo的工作目录即可 无需使用 new ZipFile(args)处理,运行模式可以通过event.getPlugin().getRuntimeMode()来获取

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

@guqing
Copy link
Owner

guqing commented Feb 26, 2022

hi @cooker 此PR是否还在继续

@guqing
Copy link
Owner

guqing commented Apr 5, 2022

此 PR 太久未活跃 我将关闭它 如有后续可以重新open

@guqing guqing closed this Apr 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants