Canapin
(Coin-coin le Canapin)
9월 17, 2020, 1:46오후
1
안녕하세요!
buildQuote 함수를 수정하여 [quote] 태그가 시작되기 전에 새로운 줄을 추가해 보고 싶습니다.
구체적으로, 다음 코드를:
return `[quote="${params.join(", ")}"]\n${contents.trim()}\n[/quote]\n\n`;
다음과 같이 변경하고 싶습니다:
return `\n[quote="${params.join(", ")}"]\n${contents.trim()}\n[/quote]\n\n`;
테마 구성 요소(theme component)로 이런 작업을 할 수 있을까요? 이 함수를 오버라이드하는 방법은 무엇인가요?
Canapin
(Coin-coin le Canapin)
9월 17, 2020, 4:03오후
2
성공적으로 구현은 했는데, 더 깔끔한 방법이 있을까요?
<script type="text/discourse-plugin" version="0.8.23">
function buildQuote(post, contents, opts = {}) {
if (!post || !contents) {
return "";
}
const params = [
opts.username || post.username,
`post:${opts.post || post.post_number}`,
`topic:${opts.topic || post.topic_id}`
];
if (opts.full) params.push("full:true");
return `\n[quote="${params.join(", ")}"]\n${contents.trim()}\n[/quote]\n\n`;
}
api.modifyClass('controller:composer', {
actions: {
importQuote(toolbarEvent) {
const postStream = this.get("topic.postStream");
let postId = this.get("model.post.id");
// 현재 게시물이 없으면 스트림의 첫 번째 게시물 ID를 사용합니다
if (!postId && postStream) {
postId = postStream.get("stream.firstObject");
}
// 게시물을 편집 중이라면, 인용을 가져올 때 답글을 가져옵니다
if (this.get("model.editingPost")) {
const replyToPostNumber = this.get("model.post.reply_to_post_number");
if (replyToPostNumber) {
const replyPost = postStream.posts.findBy(
"post_number",
replyToPostNumber
);
if (replyPost) {
postId = replyPost.id;
}
}
}
if (postId) {
this.set("model.loading", true);
return this.store.find("post", postId).then(post => {
const quote = buildQuote(post, post.raw, {
full: true
});
toolbarEvent.addText(quote);
this.set("model.loading", false);
});
}
}
}
});
</script>
asc
2월 27, 2023, 11:10오후
3
오래된 주제를 다시 올리는 점 죄송합니다만, 이 방법이 여전히 작동하시나요? 아니면 업데이트가 필요하셨나요? 이 기능을 작동시키려고 계속 시도하고 있는데, 아예 발동조차 되지 않네요. modifyClass와 관련된 모든 작업에서 정말 고생을 하고 있어서요.
Canapin
(Coin-coin le Canapin)
2월 28, 2023, 8:05오전
4
asc:
하지만 이 기능이 여전히 작동하나요?
방금 테스트해봤는데, 여전히 작동합니다
정말 그대로 제 테마에 복사해서 붙여넣었는데, 아무 수정 없이 바로 작동했습니다.
asc
2월 28, 2023, 2:10오후
6
@merefield님과 @Canapin님 감사합니다. Discourse 플러그인 API를 배우려고 이런 단순해 보이는 것들을 이것저것 시도해 보고 있는데, modifyClass가 작동할 때와 안 할 때가 너무 일관성이 없어서 답답합니다. @merefield님이 언급해 주신 작은 테마 컴포넌트가 하나 있는데, 거기서 modifyClass 호출 두 번은 잘 동작하는데 세 번째는 안 됩니다. 제 코드가 잘못된 건지, 아니면 그냥 modifyClass의 문제인지 파악하는 게 정말 스트레스입니다.
다른 주제를 꺼낸 점 죄송합니다. @Canapin님 빠른 답변 감사합니다.
업데이트:
Canapin
(Coin-coin le Canapin)
2월 28, 2023, 2:16오후
7
걱정 마세요. OT가 무슨 뜻인지는 모르겠지만, 도와드리기 위해 여기 있으니까요!