Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/npm_and_yarn/tailwindcss/typograp…
Browse files Browse the repository at this point in the history
…hy-0.5.13
  • Loading branch information
tbrlpld authored Jul 28, 2024
2 parents 848cff6 + 83f4136 commit 8995950
Show file tree
Hide file tree
Showing 104 changed files with 922 additions and 352 deletions.
7 changes: 3 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ ENV PATH=${POETRY_HOME}/bin:$PATH \
PORT=8000
RUN env

# Install litestream (https://litestream.io/install/debian/)
ARG PLATFORM=amd64
RUN wget https://github.com/benbjohnson/litestream/releases/download/v0.3.9/litestream-v0.3.9-linux-$PLATFORM.deb
RUN dpkg -i litestream-v0.3.9-linux-$PLATFORM.deb
# Install litestream
COPY ./scripts/install-litestream.sh ./scripts/
RUN ./scripts/install-litestream.sh

# Install poetry
RUN curl -sSL https://install.python-poetry.org | python3 -
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ Once your app is working, and you have TLS in place, you also configure:

This project is using SQLite as it's database -- even in production 😱.
Using SQLite is often discouraged to be used in production.
Those concerns a usually based on the abilitiy to handle multiple writes and how to backup the database.
Those concerns a usually based on the ability to handle multiple writes and how to backup the database.
For container deployments on a platform as a service (such as Heroku) there is also the problem of persisting the database between container restarts.

The write ability is not really an issue for this application.
Since this app is mainly a content site with few editors working simulaneously (if ever) it is much more read-heavy than write-heavy.
Since this app is mainly a content site with few editors working simultaneously (if ever), it is much more read-heavy than write-heavy.
Reads are easy for SQLite to handle.

The persistence problem does apply to this app though.
Expand Down
2 changes: 0 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ services:
build:
context: .
target: backend-development
args:
- PLATFORM=arm64
command: ["tail", "-f", "/dev/null"]
env_file:
- .env
Expand Down
109 changes: 107 additions & 2 deletions lpld/core/blocks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from wagtail import blocks
from wagtail.admin import panels
from wagtail.templatetags import wagtailcore_tags


class HeadingBlock(blocks.StructBlock):
Expand All @@ -8,15 +9,119 @@ class HeadingBlock(blocks.StructBlock):
panels = [panels.FieldPanel("text", classname="full")]

class Meta:
template = "atoms/heading/heading-block.html"
template = "atoms/heading/heading.html"
icon = "title"

def get_context(self, value, parent_context=None):
return {
"level": 2,
"children": value.get("text"),
}


class SubheadingBlock(blocks.StructBlock):
text = blocks.CharBlock(required=True)

panels = [panels.FieldPanel("text")]

class Meta:
template = "atoms/heading/subheading-block.html"
template = "atoms/heading/heading.html"
icon = "title"

def get_context(self, value, parent_context=None):
return {
"level": 3,
"children": value.get("text"),
}


class PageLinkBlock(blocks.StructBlock):
page = blocks.PageChooserBlock(required=True)
text = blocks.CharBlock(
required=False,
help_text="Text for the link. Defaults to page title.",
)

class Meta:
icon = "doc-full"
template = "atoms/link/link.html"

def get_context(self, value, parent_context=None):
page = value.get("page")
text = value.get("text")
return {
"text": text or page.title,
"href": page.get_url(),
}


class LinkStream(blocks.StreamBlock):
"""
Stream of links.
Each item should return context objects containing the keys `"text"` and `"href"`
from their `get_context` method.
"""

page_link = PageLinkBlock()

class Meta:
icon = "list-ul"
template = "molecules/link-listing/link-listing.html"
min_num = 1

def get_context(self, value, parent_context=None):
links = [bb.block.get_context(bb.value) for bb in value]
return {"links": links}


class LinkBlock(LinkStream):
"""
Link stream with max 1 item.
Can be used as a flexible link block.
"""

class Meta:
icon = "link"
template = "atoms/link/link.html"
min_num = 1
max_num = 1

def get_context(self, value, parent_context=None):
bound_block = value[0]
return bound_block.block.get_context(bound_block.value)


class SimpleProseRichtext(blocks.RichTextBlock):
def __init__(self, *args, **kwargs):
if "features" not in kwargs:
kwargs["features"] = ["link", "bold", "italics"]
super().__init__(*args, **kwargs)

class Meta:
template = "organisms/prose/prose.html"

def get_context(self, value, parent_context=None) -> dict[str, str]:
return {"children": wagtailcore_tags.richtext(value)}


class SectionBlock(blocks.StructBlock):
heading = HeadingBlock()
body = blocks.StreamBlock(
local_blocks=[
("paragraph", SimpleProseRichtext()),
("link_list", LinkStream()),
],
min_rum=1,
required=False,
)

panels = [
panels.FieldPanel("heading"),
panels.FieldPanel("body"),
]

class Meta:
template = "molecules/section/section-block.html"
icon = "bars"
29 changes: 16 additions & 13 deletions lpld/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
from wagtail import models as wagtail_models
from wagtail.admin import panels

from lpld.navigation import utils as nav_utils


class BasePage(wagtail_models.Page):
class Meta(wagtail_models.Page.Meta):
Expand All @@ -15,10 +13,22 @@ class Meta(wagtail_models.Page.Meta):
def title_tag_content(self):
return self.get_title_tag_content()

def get_title_tag_content(self):
title_text = self.seo_title or self.title
title_text = f"{ title_text } · lpld.io"
return title_text
def get_title_tag_content(self) -> str:
parts = self.get_title_tag_parts()
sep = self.get_title_separator()
return sep.join(parts)

def get_title_tag_parts(self) -> list[str]:
title = self.seo_title or self.title
last = self.get_title_tag_last_part()
return [title, last]

def get_title_tag_last_part(self) -> str:
"""Return the last part for the title tag."""
return "lpld.io"

def get_title_separator(self) -> str:
return " · "

@func_utils.cached_property
def meta_description(self):
Expand All @@ -27,13 +37,6 @@ def meta_description(self):
def get_meta_description(self):
return self.search_description or ""

def get_context(self, request):
context = super().get_context(request)
context["primary_navigation_links"] = nav_utils.get_primary_navigation_links(
request
)
return context


class AbstractLink(models.Model):
page = models.ForeignKey(
Expand Down
43 changes: 43 additions & 0 deletions lpld/home/migrations/0004_homepage_body.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Generated by Django 4.1.13 on 2024-03-09 00:37

from django.db import migrations

import wagtail.blocks
import wagtail.fields


class Migration(migrations.Migration):
dependencies = [
("home", "0003_homepage_profile_image"),
]

operations = [
migrations.AddField(
model_name="homepage",
name="body",
field=wagtail.fields.StreamField(
[
(
"section",
wagtail.blocks.StructBlock(
[
(
"heading",
wagtail.blocks.StructBlock(
[
(
"text",
wagtail.blocks.CharBlock(required=True),
)
]
),
)
]
),
)
],
blank=True,
use_json_field=True,
),
),
]
90 changes: 90 additions & 0 deletions lpld/home/migrations/0005_homepage_subtitle_alter_homepage_body.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Generated by Django 4.1.13 on 2024-07-07 23:51

from django.db import migrations, models

import wagtail.blocks
import wagtail.fields


class Migration(migrations.Migration):
dependencies = [
("home", "0004_homepage_body"),
]

operations = [
migrations.AddField(
model_name="homepage",
name="subtitle",
field=models.CharField(blank=True, max_length=50),
),
migrations.AlterField(
model_name="homepage",
name="body",
field=wagtail.fields.StreamField(
[
(
"section",
wagtail.blocks.StructBlock(
[
(
"heading",
wagtail.blocks.StructBlock(
[
(
"text",
wagtail.blocks.CharBlock(required=True),
)
]
),
),
(
"body",
wagtail.blocks.StreamBlock(
[
(
"paragraph",
wagtail.blocks.RichTextBlock(
features=["link", "bold", "italics"]
),
),
(
"link_list",
wagtail.blocks.StreamBlock(
[
(
"page_link",
wagtail.blocks.StructBlock(
[
(
"page",
wagtail.blocks.PageChooserBlock(
required=True
),
),
(
"text",
wagtail.blocks.CharBlock(
help_text="Text for the link. Defaults to page title.",
required=False,
),
),
]
),
)
]
),
),
],
min_rum=1,
required=False,
),
),
]
),
)
],
blank=True,
use_json_field=True,
),
),
]
Loading

0 comments on commit 8995950

Please sign in to comment.