Шаблон темы Canvas

:information_source: Краткое описание Быстрый старт разработки вашей темы с использованием готового шаблона.
:busts_in_silhouette: Целевая аудитория Новые разработчики, желающие начать создание тем для Discourse. Опытные разработчики, желающие использовать готовый шаблон.
:hammer_and_wrench: Репозиторий Manuel Kostka / Discourse / Canvas / Canvas Theme Template · GitLab
:eyes: Предпросмотр Темы Canvas

Canvas предоставляет гибкий шаблон, позволяющий создавать пользовательские темы с меньшим количеством кода. Легко изменяйте свойства и значения конфигурации, чтобы адаптировать тему под свои нужды.

Примеры видов


Базовый шаблон сохраняет значения по умолчанию и остаётся нейтральным в дизайне.

Минимальные изменения, модифицирующие несколько пользовательских свойств и определяющие цвет выделения:

Дизайн, интегрирующий компонент карточек тем и пользовательские стили для баннеров:

Сложная тема, включающая пользовательский шрифт и уникальные цветовые схемы:

Вариация на тему бывшей темы Central:

Использование


  1. Склонируйте шаблон темы.

  2. Синхронизируйте тему с вашим экземпляром Discourse, используя discourse_theme gem.

  3. Перейдите в административную панель и вручную измените следующие настройки компонента темы:
    Баннеры категорий
    Точка подключения плагина → above-main-container
    Баннеры тегов
    Показывать под заголовком сайта → снять галочку
    Показывать над основным контейнером → установить галочку

  4. Отредактируйте scss/properties.scss, чтобы определить значения пользовательских свойств

  5. Отредактируйте about.json, чтобы добавить ресурсы, цветовые схемы и другие компоненты темы

Более подробный обзор настройки


Шаблон Canvas Theme лишь расширяет базовую структуру темы по умолчанию, объединяя несколько компонентов темы и добавляя некоторые готовые файлы стилей. Фактические функции обрабатываются отдельным компонентом темы Canvas Settings. Этот компонент выполняет две функции:

Такая раздельная настройка позволяет создавать тему, используя шаблон Canvas, при этом получая выгоду от постоянных исправлений и обновлений, предоставляемых через компонент.

Примеры тем


Вы можете просмотреть общие примеры тем по адресу https://canvas.kostka.studio. Внизу боковой панели есть переключатель тем для изменения дизайна.

Изучите код общих примеров видов или установите их в качестве стартовой темы из следующих репозиториев:


:tada: Огромное спасибо проекту Discourse за спонсирование разработки этого проекта!

25 лайков

Those theme settings don’t show up when I tried to install the example themes. Is that expected behavior?

1 лайк

The settings are on the theme component installed as Canvas Settings. It’s maybe a bit misleading that settings are always named Theme Settings on the ui, also on theme components.

2 лайка

Found them in Canvas Settings component, thx!

3 лайка

Thanks so much for working on this @manuel.

I took the Editor version for a spin locally, it mostly works very well, but I noticed some small issues.


On a default install, without changing any settings, the tag label in the Extra Banners component shows up in the wrong place:

The category banner is also shown in the same place, above the sidebar. Latest topics, Hot topics are correctly shown in the main column.


I’m guessing it’s not a goal of the theme to fully cover the admin UI, however, the light and dark Editor color palettes have the admin sidebar looking quite different. I am curious if it is possible to harmonize with the non-admin sidebar.

5 лайков

The theme is meant to show banners next to the sidebar, using the above-main-container outlet. The Extra-Banners component uses that outlet by default, but the two components for Category and Tag banners are by default rendered below the header. I wouldn’t want to fork these components, just to set a different default outlet… That’s why I put these instructions:

But if that’s easy to miss, maybe there’s a better way to put it? :thinking:

Yeah, that’s easy enough and seems a good approach for this theme. I just added a commit!

5 лайков

Ah yes, I see how we got here. We don’t necessarily want to change the defaults in the category/tag banners components, don’t want to fork them either. Tricky to fix, let’s leave it as is for now and see if others run into the same issue.

Admin sidebar change looks good already, thanks!

4 лайка

Could these instructions be elaborated a bit? Is it not possible to just install from the admin UI? Thx :pray:t4:

EDIT: I installed via the admin UI and it seems to be working except there doesn’t seem to be anywhere to edit scss now

EDIT: nevermind, I see that is probably expected and you’re showing to edit the theme files directly. I wonder if it could be on the roadmap for this to happen via the admin ui? Like, have a variables editor same as you have a settings editor

3 лайка

I don’t know what’s on the core roadmap, but one thing you could do right now is create a new theme component right on the admin UI:

And then declare custom properties on it’s CSS file. You could either look up properties on the Readme file. Or copy the contents of properties.scss from the theme repo.

2 лайка

How do I clone this to Gihub? Still a bit on the green side :wink:

You could import it through the UI:

However, if you want to be able to sync changes, I believe you’d need to pull to a local clone and then push from it. Something like this:

  1. Clone from GitLab
git clone "https://gitlab.com/manuelkostka/discourse/canvas/theme.git"
  1. Set push URL to your GitHub repo
git remote set-url --push origin "git@github.com:Username/Reponame.git"
  1. Then you can periodically fetch from GitLab and push to GitHub
git fetch -p origin
git push origin
2 лайка

I don’t see a plus on mobile on GitHub. May need to try the command lines when Home.

All I see in GitHub on dashboard is option to create a new repo but no claim ne option. I am on free account so not sure if that might have something to do with it.

I added a component that lets you define a few style variables and layout options right on the component ui:

It’s limited compared to declaring custom variables on the stylesheet. But it lets you tinker with a few different looks. Curious to hear if that works! :eyes:

2 лайка

I’m playing with it right now and I think it’s nice! Is there a way to reduce the line spacing of the menu - to make it more compact?

Also, I can’t scroll the solid sidebar, is this by mistake?

2 лайка

I just adjusted the CSS styles for the solid sidebar, scrolling should work again!

However, the solid sidebar is just one of the options on the Styles component I mentioned on the post above. If you want to adjust more styles (like spacing the sidebar menu), you’d need to follow the approach explained above in Usage and A closer look at the Setup: Use your own stylesheet with CSS custom properties – in this case that would be -d-sidebar-row-height.

3 лайка

I’ve put together a new example theme based on this template. As the name suggests, this one’s a tribute to the original Central theme! :hugs: :partying_face:

I loved the layout and visual style of Central and I’ve been packaging some of its features into standalone components, like the Custom User Menu and several sidebar blocks.

I realized that with the sidebar and some styles, this template actually gets you a good way towards the original theme’s look and feel.


In any case, I’m not planning to fully re-build the Central theme.. but I might still experiment with a dedicated topic list style down the road. If you’re curious and want to take a look, the theme is also live here, select it using the sidebar theme toggle: https://canvas.kostka.studio

8 лайков

Very nice. Thanks for sharing.

1 лайк

Thanks for sharing this template! The flexibility with components and the clean design make it really easy to customize. Looking forward to trying it out on my own instance.

2 лайка

Welcome to Discourse :discourse: !

2 лайка

Поскольку обновление Foundation скоро станет новым стандартом, будет ли шаблон темы Canvas обновлён для использования тех же «оснований» (eh), или он сохранит текущий стиль, очень близкий к нынешней (скоро устаревающей) теме Foundation?

1 лайк