From 5e3746eb51de85fe90de4e869c06137bad085c99 Mon Sep 17 00:00:00 2001 From: Konstantin Kostov Date: Thu, 14 Mar 2024 04:04:59 +0100 Subject: [PATCH] Allow code blocks inside blogposts --- blog/blocks.py | 5 ++++- blog/migrations/0009_alter_blogpage_body.py | 20 ++++++++++++++++++++ iamkonstantin_web/settings/base.py | 20 +++++++++++++++++++- requirements.txt | 3 ++- 4 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 blog/migrations/0009_alter_blogpage_body.py diff --git a/blog/blocks.py b/blog/blocks.py index 3075361..2a2690d 100644 --- a/blog/blocks.py +++ b/blog/blocks.py @@ -1,5 +1,8 @@ from wagtail.blocks import RichTextBlock from base.blocks import StreamBlock +from wagtailcodeblock.blocks import CodeBlock + class BlogPostBlock(StreamBlock): - paragraph = RichTextBlock(blank=True) \ No newline at end of file + paragraph = RichTextBlock(blank=True) + code = CodeBlock(label='Code snippet') diff --git a/blog/migrations/0009_alter_blogpage_body.py b/blog/migrations/0009_alter_blogpage_body.py new file mode 100644 index 0000000..a70bff5 --- /dev/null +++ b/blog/migrations/0009_alter_blogpage_body.py @@ -0,0 +1,20 @@ +# Generated by Django 5.0.2 on 2024-03-14 02:57 + +import wagtail.blocks +import wagtail.fields +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('blog', '0008_alter_blogpage_body'), + ] + + operations = [ + migrations.AlterField( + model_name='blogpage', + name='body', + field=wagtail.fields.StreamField([('paragraph', wagtail.blocks.RichTextBlock(blank=True)), ('code', wagtail.blocks.StructBlock([('language', wagtail.blocks.ChoiceBlock(choices=[('bash', 'Bash/Shell'), ('css', 'CSS'), ('diff', 'diff'), ('html', 'HTML'), ('javascript', 'Javascript'), ('json', 'JSON'), ('python', 'Python'), ('scss', 'SCSS'), ('yaml', 'YAML')], help_text='Coding language', identifier='language', label='Language')), ('code', wagtail.blocks.TextBlock(identifier='code', label='Code'))], label='Code snippet'))], blank=True, help_text='Write anything'), + ), + ] diff --git a/iamkonstantin_web/settings/base.py b/iamkonstantin_web/settings/base.py index cb8186f..9831ee6 100644 --- a/iamkonstantin_web/settings/base.py +++ b/iamkonstantin_web/settings/base.py @@ -29,6 +29,7 @@ INSTALLED_APPS = [ "blog", "home", "search", + "wagtailcodeblock", "wagtail.contrib.settings", "wagtail.contrib.forms", "wagtail.contrib.redirects", @@ -177,4 +178,21 @@ WAGTAILSEARCH_BACKENDS = { # Base URL to use when referring to full URLs within the Wagtail admin backend - # e.g. in notification emails. Don't include '/admin' or a trailing slash -WAGTAILADMIN_BASE_URL = "http://example.com" +WAGTAILADMIN_BASE_URL = "https://iamkonstantin.eu" + +WAGTAIL_CODE_BLOCK_LANGUAGES = ( + ('bash', 'Bash/Shell'), + ('css', 'CSS'), + ('dart', 'Dart'), + ('elixir', 'Elixir'), + ('go', 'Go'), + ('html', 'HTML'), + ('javascript', 'Javascript'), + ('json', 'JSON'), + ('kotlin', 'Kotlin'), + ('python', 'Python'), + ('swift', 'Swift'), + ('yaml', 'YAML'), +) + +WAGTAIL_CODE_BLOCK_THEME = 'twilight' \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index fbafcd3..4d9c980 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ Django>=4.2,<5.1 wagtail>=6.0,<6.1 -whitenoise>=6.6,<7.0 \ No newline at end of file +whitenoise>=6.6,<7.0 +wagtailcodeblock>=1.29.0.2,<2.0 \ No newline at end of file