omppatil
(Om Patil)
28.Ноябрь.2023 12:34:55
1
Привет!
Я новичок в создании плагинов для Discourse и был бы признателен за помощь в добавлении кнопки переключения в меню поста и реализации её действия в плагине.
Lilly
(Lillian )
28.Ноябрь.2023 12:41:05
2
Привет @omppatil , возможно, этот пост поможет вам двигаться в правильном направлении:
Если вы хотите добавить кнопку в меню поста, вам понадобится немного другой подход, поскольку посты являются виджетами .
Вам нужно будет добавить что-то вроде этого в вашу тему или плагин.
api.addPostMenuButton("my-button", () => {
return {
action: "someAction",
icon: "someIcon",
className: "someClass",
title: "some title",
};
});
API плагинов содержит метод для добавления новых кнопок, что делает эту задачу относительно простой.
discourse/app/assets/javascripts/discourse/…
Также, если вы новичок в разработке плагинов для Discourse:
I’ve only just started but here’s my ‘starter for 10’ to get you going:
Read:
these
this
Try and read the code on the simplest, but popular plugins and see if you can understand what they are doing (this is not always easy, especially with the complexity of dealing with multiple files and the sometimes brutal functional brevity of javasctipt, but persevere)
You need to learn:
Lots of Javascript (look no further than @mpj ’s Fun Fun Function excellent & fun (!) videos (thanks man!))
Lots of …
There are a few ‘how to start’ guides for working with Discourse already and a wealth of useful info on meta, but I thought it might help to give an insight to the mental processes of starting from little, if any, prior coding experience to building substantial Discourse plugins.
Discourse is written by experienced developers and has a large codebase. This can feel intimidating. This intimidation factor can be a significant barrier for novice developers. This is a kind of ‘psychological primer’…
Привет!
Вы можете использовать addPostMenuButton.
api.addPostMenuButton('coffee', () => {
return {
action: 'drinkCoffee',
icon: 'coffee',
className: 'hot-coffee',
title: 'coffee.title',
position: 'first' // может быть `first`, `last` или `second-last-hidden`
};
});
Затем вы можете добавить своё действие следующим образом:
api.attachWidgetAction("post", "drinkCoffee", function () {
//
}
РЕДАКТИРОВАНИЕ: Получил «Лиллиан» . Также было бы хорошей идеей ознакомиться с руководствами, которые опубликовала Лилли!
omppatil
(Om Patil)
28.Ноябрь.2023 12:53:27
4
Следовательно, какую файловую структуру следует реализовать и где должен быть размещен приведенный выше код?
Lilly
(Lillian )
28.Ноябрь.2023 13:26:19
5
Прочтение тем, на которые приведены ссылки выше, должно ответить на ваши вопросы по разработке. Возможно, вы сможете реализовать то, что хотите, с помощью компонента темы вместо плагина. Поэтому я также рекомендую добавить в ваш список для чтения следующие материалы:
Это краткий курс по основам тем Discourse. Целевая аудитория — все, кто не знаком с темами Discourse. Если вы уже использовали темы или компоненты тем Discourse, вам, вероятно, не нужно читать это руководство.
Что такое темы и компоненты тем?
Тема или компонент темы — это набор файлов, упакованных вместе, предназначенных для визуального изменения Discourse или добавления новых функций.
Начнем с тем.
Темы
Как правило, темы не должны быть совместимы друг с другом, поскольку по сути представляю…
Discourse Themes and Theme Components can be used to customize the look, feel and functionality of Discourse’s frontend. This section of the developer guides aims to provide all the reference materials you need to develop simple themes for a single site, right up to complex open-source theme components.
This introduction aims to provide a map of all the tools and APIs for theme development. If you prefer a step-by-step tutorial for theme development, jump straight to:
Themes vs. Theme Compon…
Кроме того, из первой ссылки, которую я привёл: