bitmage
(Brandon Mason)
4월 6, 2025, 2:39오전
1
저는 테마 또는 플러그인 (둘 다 사용 중)의 일부로 이미지 아이콘을 업로드하고 싶습니다. 이후에는 플러그인 내의 글리머(glimmer) 컴포넌트에서 이를 참조할 예정입니다. ajax 요청을 통해 다른 서버로 보내야 하므로, 이미지 위치의 문자열 URL을 가져올 수 있어야 합니다. (참고로, 원격 서버는 아이콘을 QR 코드에 임베드합니다.)
테마 의 about.json에 이미지를 넣으면 결정론적인(deterministic) 위치에 배치되지 않고, 대신 URL에 해시가 포함됩니다. 따라서 CSS를 제외하고는 어떻게 참조해야 할지 모르겠으며, 플러그인에서 참조하는 것은 더더욱 어렵습니다.
플러그인 의 관리자 설정에 uploaded_image_list로 이미지를 넣으면 위치 역시 결정론적이지 않고, 게다가 사람이 읽을 수 있는 이름/태그/별명 없이 배열에 들어가기 때문에 참조할 방법이 없습니다.
// console.log(this.siteSettings.county_fence_available_icons):
/uploads/default/original/1X/1764ca1c70c7f4f7f01da26e702639fd8cfe2bf4.jpeg|/uploads/default/original/1X/b16cecd70e4d25abdf06a8b6135ec126d2c6ce2d.jpeg|/uploads/default/original/1X/b4c049256c1068e531e43f1622ada78c5b2070b3.jpeg|/uploads/default/original/1X/4aa457c9cd939e178eb251682a4438cc027b96e9.jpeg
그러면 테마나 플러그인에 이미지를 업로드할 때 결정론적인 URL에 배치되도록 하는 방법이 있을까요?
이 질문은 사용자가 업로드하려는 기타 모든 자산에도 해당됩니다. about.json의 assets 섹션과 plugin.rb에서 사용될 register_asset 함수는 폰트 외의 다른 파일 유형도 처리할 수 있을 것 같아 보이지만, 해당 파일이 업로드된 경우 어디에 있는지 전혀 알 수 없습니다.
pfaffman
(Jay Pfaffman)
4월 6, 2025, 9:31오후
2
아니요. 이전처럼 변수 이름으로 참조하나요? 모든 업로드된 파일은 콘텐츠의 해시로 저장됩니다.
Themes and theme components allow you to handle uploaded assets such as images and fonts. You can control what assets your theme accepts using the site setting: theme authorized extensions
Including assets in themes and components
For remote themes
Remote themes include:
Themes and components installed from the Popular list of themes
Themes and components installed using the From a git repository method
To upload assets to a remote theme or theme component, see Create and share a font theme …
RGJ
(Richard - Communiteq)
4월 6, 2025, 9:47오후
3
URL을 설정 할 수는 없지만, URL은 파일의 SHA1 해시로 구성되므로 *결정적(deterministic)*입니다.
파일 내용을 변경하지 않는 한, 이미지는 다음 중 하나의 위치에 저장되어야 합니다.
/uploads/<instance name>/original/1X/1764ca1c70c7f4f7f01da26e702639fd8cfe2bf4.jpeg
또는
/uploads/<instance name>/original/2X/1/1764ca1c70c7f4f7f01da26e702639fd8cfe2bf4.jpeg
또는
/uploads/<instance name>/original/3X/1/7/1764ca1c70c7f4f7f01da26e702639fd8cfe2bf4.jpeg
또는
/uploads/<instance name>/original/4X/1/7/6/1764ca1c70c7f4f7f01da26e702639fd8cfe2bf4.jpeg
(어떤 경로가 될지는 이미 가지고 있는 업로드 파일 수에 따라 결정됩니다.)
Alteras
(Steven Chang)
4월 6, 2025, 9:48오후
4
플러그인의 경우, 관리자 설정으로 수정할 수 없는 하드 에셋(하드 에셋)에는 명확한 URL이 제공됩니다.
Discourse Math 플러그인의 초기화 파일을 참조할 수 있습니다:
import loadScript from "discourse/lib/load-script";
import { withPluginApi } from "discourse/lib/plugin-api";
async function ensureKaTeX() {
try {
await loadScript("/plugins/discourse-math/katex/katex.min.js");
await loadScript("/plugins/discourse-math/katex/katex.min.css", {
css: true,
});
await loadScript("/plugins/discourse-math/katex/mhchem.min.js");
await loadScript("/plugins/discourse-math/katex/copy-tex.min.js");
} catch (e) {
// eslint-disable-next-line no-console
console.error("Failed to load KaTeX dependencies.", e);
}
}
function decorate(elem, katexOpts) {
katexOpts["displayMode"] = elem.tagName === "DIV";
This file has been truncated. show original
/public 디렉토리에 있는 에셋은 플러그인 이름 아래에서 사용할 수 있습니다. 이러한 에셋은 plugin.rb에 등록할 필요 없이 직접 호출됩니다.