koishi-plugin-rocom 1.0.6 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/render.js CHANGED
@@ -60,36 +60,53 @@ class Renderer {
60
60
  this.resPath = resPath;
61
61
  }
62
62
  resourceUrl(relativePath) {
63
- return (0, node_url_1.pathToFileURL)(node_path_1.default.join(this.getResourceRoot(), relativePath)).href;
63
+ return (0, node_url_1.pathToFileURL)(node_path_1.default.join(this.getPreferredResourceRoot(), relativePath)).href;
64
64
  }
65
- getResourceRoot() {
65
+ getPreferredResourceRoot() {
66
66
  const builtRoot = node_path_1.default.join(this.resPath, 'lib');
67
67
  if (node_fs_1.default.existsSync(node_path_1.default.join(builtRoot, 'render-templates')))
68
68
  return builtRoot;
69
69
  return node_path_1.default.join(this.resPath, 'src');
70
70
  }
71
- getTemplateRoot() {
72
- return node_path_1.default.join(this.getResourceRoot(), 'render-templates');
71
+ getTemplateCandidateRoots() {
72
+ const roots = [
73
+ node_path_1.default.join(this.resPath, 'lib'),
74
+ node_path_1.default.join(this.resPath, 'src'),
75
+ ];
76
+ return Array.from(new Set(roots));
73
77
  }
74
- getTemplatePath(templateName) {
75
- const directHtmlPath = node_path_1.default.join(this.getTemplateRoot(), `${templateName}.html`);
76
- if (node_fs_1.default.existsSync(directHtmlPath))
77
- return directHtmlPath;
78
- return node_path_1.default.join(this.getTemplateRoot(), templateName, 'index.html');
78
+ resolveTemplatePath(templateName) {
79
+ for (const root of this.getTemplateCandidateRoots()) {
80
+ const templateRoot = node_path_1.default.join(root, 'render-templates');
81
+ const directHtmlPath = node_path_1.default.join(templateRoot, `${templateName}.html`);
82
+ if (node_fs_1.default.existsSync(directHtmlPath)) {
83
+ return { templatePath: directHtmlPath, resourceRoot: root };
84
+ }
85
+ const indexHtmlPath = node_path_1.default.join(templateRoot, templateName, 'index.html');
86
+ if (node_fs_1.default.existsSync(indexHtmlPath)) {
87
+ return { templatePath: indexHtmlPath, resourceRoot: root };
88
+ }
89
+ }
90
+ return null;
79
91
  }
80
92
  getStylePath(templateName) {
81
- return node_path_1.default.join(this.getTemplateRoot(), templateName, 'style.css');
93
+ const resolved = this.resolveTemplatePath(templateName);
94
+ if (!resolved)
95
+ return '';
96
+ return node_path_1.default.join(resolved.resourceRoot, 'render-templates', templateName, 'style.css');
82
97
  }
83
98
  async renderHtml(ctx, templateName, data) {
84
99
  try {
85
- const templatePath = this.getTemplatePath(templateName);
86
- if (!node_fs_1.default.existsSync(templatePath)) {
87
- logger.error(`template file missing: ${templatePath}`);
100
+ const resolvedTemplate = this.resolveTemplatePath(templateName);
101
+ if (!resolvedTemplate) {
102
+ const checked = this.getTemplateCandidateRoots().map(root => node_path_1.default.join(root, 'render-templates', templateName));
103
+ logger.error(`template file missing: ${checked.join(' | ')}`);
88
104
  return null;
89
105
  }
106
+ const { templatePath, resourceRoot } = resolvedTemplate;
90
107
  const templateContent = node_fs_1.default.readFileSync(templatePath, 'utf-8');
91
108
  const normalizedTemplateContent = normalizeTemplateResourcePaths(templateContent);
92
- const resPathUrl = toDirectoryFileUrl(this.getResourceRoot());
109
+ const resPathUrl = toDirectoryFileUrl(resourceRoot);
93
110
  const renderData = { ...data, _res_path: resPathUrl, pluResPath: resPathUrl };
94
111
  const html = template.render(normalizedTemplateContent, renderData);
95
112
  if (!ctx.puppeteer?.page) {
@@ -153,6 +170,8 @@ class Renderer {
153
170
  '.student-page',
154
171
  '.merchant-page',
155
172
  '.home-page',
173
+ '.pet-panel-page',
174
+ '.pet-detail-page',
156
175
  ];
157
176
  let target = null;
158
177
  for (const selector of selectors) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-rocom",
3
3
  "description": "洛克王国查询与订阅插件",
4
- "version": "1.0.6",
4
+ "version": "1.0.7",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "homepage": "https://github.com/staytomorrow/koishi-plugin-rocom",