diff options
author | Jonathan DeMasi <jonathan.demasi@colorado.edu> | 2020-03-14 10:12:11 -0600 |
---|---|---|
committer | Jonathan DeMasi <jonathan.demasi@colorado.edu> | 2020-03-14 10:12:11 -0600 |
commit | 98212b920434ff16877fe824ef34d9e72cec0349 (patch) | |
tree | 051d8c03934aa444c7ab99037cb09810ff25b915 /blog | |
parent | 2d8732c77bf5e321fb447cb507be8df4c3052dd2 (diff) | |
download | jthanio-98212b920434ff16877fe824ef34d9e72cec0349.tar jthanio-98212b920434ff16877fe824ef34d9e72cec0349.tar.gz jthanio-98212b920434ff16877fe824ef34d9e72cec0349.tar.bz2 jthanio-98212b920434ff16877fe824ef34d9e72cec0349.tar.lz jthanio-98212b920434ff16877fe824ef34d9e72cec0349.tar.xz jthanio-98212b920434ff16877fe824ef34d9e72cec0349.tar.zst jthanio-98212b920434ff16877fe824ef34d9e72cec0349.zip |
custom code blocks with less bullshit
Diffstat (limited to 'blog')
-rw-r--r-- | blog/blocks.py | 22 | ||||
-rw-r--r-- | blog/migrations/0012_auto_20200314_1609.py | 24 | ||||
-rw-r--r-- | blog/models.py | 2 | ||||
-rw-r--r-- | blog/templates/blog/blog_post.html | 7 | ||||
-rw-r--r-- | blog/templates/blog/code_block.html | 5 |
5 files changed, 59 insertions, 1 deletions
diff --git a/blog/blocks.py b/blog/blocks.py new file mode 100644 index 0000000..2a313ed --- /dev/null +++ b/blog/blocks.py @@ -0,0 +1,22 @@ +from wagtail.core import blocks + +CODE_CHOICES = [ + ('python', 'python'), + ('javascript', 'javascript'), + ('css', 'css'), + ('markup', 'markup'), + ('html', 'html'), + ('go', 'go'), + ('bash', 'bash'), +] + + +class CodeBlock(blocks.StructBlock): + language = blocks.ChoiceBlock(choices=CODE_CHOICES, default="bash") + text = blocks.TextBlock() + + class Meta: + template = "blog/code_block.html" + icon = "openquote" + label = "Code Block" + diff --git a/blog/migrations/0012_auto_20200314_1609.py b/blog/migrations/0012_auto_20200314_1609.py new file mode 100644 index 0000000..bb7cf62 --- /dev/null +++ b/blog/migrations/0012_auto_20200314_1609.py @@ -0,0 +1,24 @@ +# Generated by Django 3.0.3 on 2020-03-14 16:09 + +from django.db import migrations +import wagtail.contrib.table_block.blocks +import wagtail.core.blocks +import wagtail.core.fields +import wagtail.documents.blocks +import wagtail.embeds.blocks +import wagtail.images.blocks + + +class Migration(migrations.Migration): + + dependencies = [ + ('blog', '0011_auto_20200313_0421'), + ] + + operations = [ + migrations.AlterField( + model_name='blogpost', + name='body', + field=wagtail.core.fields.StreamField([('heading', wagtail.core.blocks.CharBlock(classname='full title')), ('paragraph', wagtail.core.blocks.RichTextBlock(features=['bold', 'italic', 'code', 'strikethrough', 'superscript', 'subscript', 'h2', 'h3', 'h4', 'h5', 'ol', 'ul', 'blockquote', 'hr', 'embed', 'link', 'document-link', 'image'])), ('image', wagtail.images.blocks.ImageChooserBlock()), ('page', wagtail.core.blocks.PageChooserBlock()), ('document', wagtail.documents.blocks.DocumentChooserBlock()), ('media', wagtail.embeds.blocks.EmbedBlock()), ('html', wagtail.core.blocks.RawHTMLBlock(label='Raw HTML')), ('code', wagtail.core.blocks.StructBlock([('language', wagtail.core.blocks.ChoiceBlock(choices=[('python', 'python'), ('javascript', 'javascript'), ('css', 'css'), ('markup', 'markup'), ('html', 'html'), ('go', 'go'), ('bash', 'bash')])), ('text', wagtail.core.blocks.TextBlock())], label='Code')), ('table', wagtail.contrib.table_block.blocks.TableBlock(template='blog/table_template.html'))]), + ), + ] diff --git a/blog/models.py b/blog/models.py index 973d69b..e56b0c3 100644 --- a/blog/models.py +++ b/blog/models.py @@ -10,13 +10,13 @@ from wagtail.documents.blocks import DocumentChooserBlock from wagtail.embeds.blocks import EmbedBlock from wagtail.images.blocks import ImageChooserBlock from wagtail.core import blocks -from wagtailcodeblock.blocks import CodeBlock from modelcluster.fields import ParentalKey, ParentalManyToManyField from modelcluster.contrib.taggit import ClusterTaggableManager from wagtail.contrib.table_block.blocks import TableBlock from taggit.models import TaggedItemBase from wagtail.snippets.models import register_snippet +from blog.blocks import CodeBlock # RTF formatting options. Thanks, Ethan! :-) features = [ diff --git a/blog/templates/blog/blog_post.html b/blog/templates/blog/blog_post.html index e328308..32a3f1b 100644 --- a/blog/templates/blog/blog_post.html +++ b/blog/templates/blog/blog_post.html @@ -5,6 +5,13 @@ {% load wagtailcore_tags wagtailimages_tags %} {% block body_class %}template-blogpage{% endblock %} +{% block extra_js %} + <script src="{% static 'js/prism.js' %}"></script> +{% endblock %} +{% block extra_css %} + <link rel="stylesheet" type="text/css" href="{% static 'css/prism.css' %}"> + <link rel="stylesheet" type="text/css" href="{% static 'css/prism-okaidia.min.css' %}"> +{% endblock %} {% block content %} <div class="container"> diff --git a/blog/templates/blog/code_block.html b/blog/templates/blog/code_block.html new file mode 100644 index 0000000..f639bc4 --- /dev/null +++ b/blog/templates/blog/code_block.html @@ -0,0 +1,5 @@ +{% load wagtailcore_tags %} +<section> +{# do not indent the "{{ self.text.}}" code below, or else 'prism' will add that indentation to the first line outputted :-) #} + <pre><code class="language-{{ self.language }}">{{ self.text }}</code></pre> +</section> |