diff --git a/.env.example b/.env.example index ca6f65bb..7769a67b 100644 --- a/.env.example +++ b/.env.example @@ -89,3 +89,19 @@ PREVIEW_TEXT_COLOR=#363636 PREVIEW_IMG_WIDTH=1200 PREVIEW_IMG_HEIGHT=630 PREVIEW_DEFAULT_COVER_COLOR=#002549 + +# Below are example keys if you want to enable automatically +# sending telemetry to an OTLP-compatible service. Many of +# the main monitoring apps have OLTP collectors, including +# NewRelic, DataDog, and Honeycomb.io - consult their +# documentation for setup instructions, and what exactly to +# put below! +# +# Service name is an arbitrary tag that is attached to any +# data sent, used to distinguish different sources. Useful +# for sending prod and dev metrics to the same place and +# keeping them separate, for instance! + +OTEL_EXPORTER_OTLP_ENDPOINT= # API endpoint for your provider +OTEL_EXPORTER_OTLP_HEADERS= # Any headers required, usually authentication info +OTEL_SERVICE_NAME= # Service name to identify your app diff --git a/.github/workflows/lint-frontend.yaml b/.github/workflows/lint-frontend.yaml index 54cac04d..7041c48b 100644 --- a/.github/workflows/lint-frontend.yaml +++ b/.github/workflows/lint-frontend.yaml @@ -1,5 +1,5 @@ # @url https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions -name: Lint Frontend +name: Lint Frontend (run `./bw-dev stylelint` to fix css errors) on: push: @@ -8,7 +8,7 @@ on: - '.github/workflows/**' - 'static/**' - '.eslintrc' - - '.stylelintrc' + - '.stylelintrc.js' pull_request: branches: [ main, ci, frontend ] @@ -22,17 +22,16 @@ jobs: - uses: actions/checkout@v2 - name: Install modules - run: yarn + run: npm install stylelint stylelint-config-recommended stylelint-config-standard stylelint-order eslint # See .stylelintignore for files that are not linted. - name: Run stylelint run: > - yarn stylelint bookwyrm/static/**/*.css \ - --report-needless-disables \ - --report-invalid-scope-disables + npx stylelint bookwyrm/static/css/*.css \ + --config dev-tools/.stylelintrc.js # See .eslintignore for files that are not linted. - name: Run ESLint run: > - yarn eslint bookwyrm/static \ + npx eslint bookwyrm/static \ --ext .js,.jsx,.ts,.tsx diff --git a/.github/workflows/prettier.yaml b/.github/workflows/prettier.yaml index 80696060..c4a031db 100644 --- a/.github/workflows/prettier.yaml +++ b/.github/workflows/prettier.yaml @@ -17,8 +17,7 @@ jobs: - uses: actions/checkout@v2 - name: Install modules - run: npm install . + run: npm install prettier - # See .stylelintignore for files that are not linted. - name: Run Prettier run: npx prettier --check bookwyrm/static/js/*.js diff --git a/.gitignore b/.gitignore index e5582694..e11bbfbe 100644 --- a/.gitignore +++ b/.gitignore @@ -24,7 +24,9 @@ .idea #Node tools -/node_modules/ +node_modules/ +package-lock.json +yarn.lock #nginx nginx/default.conf diff --git a/bookwyrm/activitypub/base_activity.py b/bookwyrm/activitypub/base_activity.py index 15ca5a93..6bee25f6 100644 --- a/bookwyrm/activitypub/base_activity.py +++ b/bookwyrm/activitypub/base_activity.py @@ -227,7 +227,7 @@ def set_related_field( model_field = getattr(model, related_field_name) if hasattr(model_field, "activitypub_field"): setattr(activity, getattr(model_field, "activitypub_field"), instance.remote_id) - item = activity.to_model() + item = activity.to_model(model=model) # if the related field isn't serialized (attachments on Status), then # we have to set it post-creation @@ -298,6 +298,7 @@ class Link(ActivityObject): mediaType: str = None id: str = None attributedTo: str = None + availability: str = None type: str = "Link" def serialize(self, **kwargs): diff --git a/bookwyrm/apps.py b/bookwyrm/apps.py new file mode 100644 index 00000000..d494877d --- /dev/null +++ b/bookwyrm/apps.py @@ -0,0 +1,54 @@ +"""Do further startup configuration and initialization""" +import os +import urllib +import logging + +from django.apps import AppConfig + +from bookwyrm import settings + +logger = logging.getLogger(__name__) + + +def download_file(url, destination): + """Downloads a file to the given path""" + try: + # Ensure our destination directory exists + os.makedirs(os.path.dirname(destination)) + with urllib.request.urlopen(url) as stream: + with open(destination, "b+w") as outfile: + outfile.write(stream.read()) + except (urllib.error.HTTPError, urllib.error.URLError): + logger.error("Failed to download file %s", url) + except OSError: + logger.error("Couldn't open font file %s for writing", destination) + except: # pylint: disable=bare-except + logger.exception("Unknown error in file download") + + +class BookwyrmConfig(AppConfig): + """Handles additional configuration""" + + name = "bookwyrm" + verbose_name = "BookWyrm" + + # pylint: disable=no-self-use + def ready(self): + """set up OTLP and preview image files, if desired""" + if settings.OTEL_EXPORTER_OTLP_ENDPOINT: + # pylint: disable=import-outside-toplevel + from bookwyrm.telemetry import open_telemetry + + open_telemetry.instrumentDjango() + + if settings.ENABLE_PREVIEW_IMAGES and settings.FONTS: + # Download any fonts that we don't have yet + logger.debug("Downloading fonts..") + for name, config in settings.FONTS.items(): + font_path = os.path.join( + settings.FONT_DIR, config["directory"], config["filename"] + ) + + if "url" in config and not os.path.exists(font_path): + logger.info("Just a sec, downloading %s", name) + download_file(config["url"], font_path) diff --git a/bookwyrm/connectors/abstract_connector.py b/bookwyrm/connectors/abstract_connector.py index 5ed57df1..d8b9c630 100644 --- a/bookwyrm/connectors/abstract_connector.py +++ b/bookwyrm/connectors/abstract_connector.py @@ -1,7 +1,11 @@ """ functionality outline for a book data connector """ from abc import ABC, abstractmethod +import imghdr +import ipaddress import logging +from urllib.parse import urlparse +from django.core.files.base import ContentFile from django.db import transaction import requests from requests.exceptions import RequestException @@ -248,6 +252,8 @@ def dict_from_mappings(data, mappings): def get_data(url, params=None, timeout=10): """wrapper for request.get""" # check if the url is blocked + raise_not_valid_url(url) + if models.FederatedServer.is_blocked(url): raise ConnectorException(f"Attempting to load data from blocked url: {url}") @@ -280,6 +286,7 @@ def get_data(url, params=None, timeout=10): def get_image(url, timeout=10): """wrapper for requesting an image""" + raise_not_valid_url(url) try: resp = requests.get( url, @@ -290,10 +297,32 @@ def get_image(url, timeout=10): ) except RequestException as err: logger.exception(err) - return None + return None, None + if not resp.ok: - return None - return resp + return None, None + + image_content = ContentFile(resp.content) + extension = imghdr.what(None, image_content.read()) + if not extension: + logger.exception("File requested was not an image: %s", url) + return None, None + + return image_content, extension + + +def raise_not_valid_url(url): + """do some basic reality checks on the url""" + parsed = urlparse(url) + if not parsed.scheme in ["http", "https"]: + raise ConnectorException("Invalid scheme: ", url) + + try: + ipaddress.ip_address(parsed.netloc) + raise ConnectorException("Provided url is an IP address: ", url) + except ValueError: + # it's not an IP address, which is good + pass class Mapping: diff --git a/bookwyrm/forms.py b/bookwyrm/forms.py index e442dbf4..564ea91b 100644 --- a/bookwyrm/forms.py +++ b/bookwyrm/forms.py @@ -1,6 +1,7 @@ """ using django model forms """ import datetime from collections import defaultdict +from urllib.parse import urlparse from django import forms from django.forms import ModelForm, PasswordInput, widgets, ChoiceField @@ -227,6 +228,34 @@ class FileLinkForm(CustomForm): model = models.FileLink fields = ["url", "filetype", "availability", "book", "added_by"] + def clean(self): + """make sure the domain isn't blocked or pending""" + cleaned_data = super().clean() + url = cleaned_data.get("url") + filetype = cleaned_data.get("filetype") + book = cleaned_data.get("book") + domain = urlparse(url).netloc + if models.LinkDomain.objects.filter(domain=domain).exists(): + status = models.LinkDomain.objects.get(domain=domain).status + if status == "blocked": + # pylint: disable=line-too-long + self.add_error( + "url", + _( + "This domain is blocked. Please contact your administrator if you think this is an error." + ), + ) + elif models.FileLink.objects.filter( + url=url, book=book, filetype=filetype + ).exists(): + # pylint: disable=line-too-long + self.add_error( + "url", + _( + "This link with file type has already been added for this book. If it is not visible, the domain is still pending." + ), + ) + class EditionForm(CustomForm): class Meta: diff --git a/bookwyrm/management/commands/erase_streams.py b/bookwyrm/management/commands/erase_streams.py index 7b807402..9d971d69 100644 --- a/bookwyrm/management/commands/erase_streams.py +++ b/bookwyrm/management/commands/erase_streams.py @@ -7,6 +7,7 @@ from bookwyrm import settings r = redis.Redis( host=settings.REDIS_ACTIVITY_HOST, port=settings.REDIS_ACTIVITY_PORT, + password=settings.REDIS_ACTIVITY_PASSWORD, db=settings.REDIS_ACTIVITY_DB_INDEX, ) diff --git a/bookwyrm/migrations/0132_alter_user_preferred_language.py b/bookwyrm/migrations/0132_alter_user_preferred_language.py new file mode 100644 index 00000000..a2f0aa6a --- /dev/null +++ b/bookwyrm/migrations/0132_alter_user_preferred_language.py @@ -0,0 +1,37 @@ +# Generated by Django 3.2.10 on 2022-02-02 20:42 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0131_merge_20220125_1644"), + ] + + operations = [ + migrations.AlterField( + model_name="user", + name="preferred_language", + field=models.CharField( + blank=True, + choices=[ + ("en-us", "English"), + ("de-de", "Deutsch (German)"), + ("es-es", "Español (Spanish)"), + ("gl-es", "Galego (Galician)"), + ("it-it", "Italiano (Italian)"), + ("fr-fr", "Français (French)"), + ("lt-lt", "Lietuvių (Lithuanian)"), + ("no-no", "Norsk (Norwegian)"), + ("pt-br", "Português do Brasil (Brazilian Portuguese)"), + ("pt-pt", "Português Europeu (European Portuguese)"), + ("sv-se", "Svenska (Swedish)"), + ("zh-hans", "简体中文 (Simplified Chinese)"), + ("zh-hant", "繁體中文 (Traditional Chinese)"), + ], + max_length=255, + null=True, + ), + ), + ] diff --git a/bookwyrm/migrations/0133_alter_listitem_notes.py b/bookwyrm/migrations/0133_alter_listitem_notes.py new file mode 100644 index 00000000..26ed10f8 --- /dev/null +++ b/bookwyrm/migrations/0133_alter_listitem_notes.py @@ -0,0 +1,21 @@ +# Generated by Django 3.2.11 on 2022-02-04 20:06 + +import bookwyrm.models.fields +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0132_alter_user_preferred_language"), + ] + + operations = [ + migrations.AlterField( + model_name="listitem", + name="notes", + field=bookwyrm.models.fields.HtmlField( + blank=True, max_length=300, null=True + ), + ), + ] diff --git a/bookwyrm/migrations/0134_announcement_display_type.py b/bookwyrm/migrations/0134_announcement_display_type.py new file mode 100644 index 00000000..ba845012 --- /dev/null +++ b/bookwyrm/migrations/0134_announcement_display_type.py @@ -0,0 +1,29 @@ +# Generated by Django 3.2.11 on 2022-02-11 18:59 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0133_alter_listitem_notes"), + ] + + operations = [ + migrations.AddField( + model_name="announcement", + name="display_type", + field=models.CharField( + choices=[ + ("white-ter", "None"), + ("primary-light", "Primary"), + ("success-light", "Success"), + ("link-light", "Link"), + ("warning-light", "Warning"), + ("danger-light", "Danger"), + ], + default="white-ter", + max_length=20, + ), + ), + ] diff --git a/bookwyrm/models/announcement.py b/bookwyrm/models/announcement.py index 498d5041..cbed38ae 100644 --- a/bookwyrm/models/announcement.py +++ b/bookwyrm/models/announcement.py @@ -2,10 +2,21 @@ from django.db import models from django.db.models import Q from django.utils import timezone +from django.utils.translation import gettext_lazy as _ from .base_model import BookWyrmModel +DisplayTypes = [ + ("white-ter", _("None")), + ("primary-light", _("Primary")), + ("success-light", _("Success")), + ("link-light", _("Link")), + ("warning-light", _("Warning")), + ("danger-light", _("Danger")), +] + + class Announcement(BookWyrmModel): """The admin has something to say""" @@ -16,6 +27,13 @@ class Announcement(BookWyrmModel): start_date = models.DateTimeField(blank=True, null=True) end_date = models.DateTimeField(blank=True, null=True) active = models.BooleanField(default=True) + display_type = models.CharField( + max_length=20, + blank=False, + null=False, + choices=DisplayTypes, + default="white-ter", + ) @classmethod def active_announcements(cls): diff --git a/bookwyrm/models/fields.py b/bookwyrm/models/fields.py index e61f912e..b506c11c 100644 --- a/bookwyrm/models/fields.py +++ b/bookwyrm/models/fields.py @@ -1,6 +1,5 @@ """ activitypub-aware django model fields """ from dataclasses import MISSING -import imghdr import re from uuid import uuid4 from urllib.parse import urljoin @@ -9,7 +8,6 @@ import dateutil.parser from dateutil.parser import ParserError from django.contrib.postgres.fields import ArrayField as DjangoArrayField from django.core.exceptions import ValidationError -from django.core.files.base import ContentFile from django.db import models from django.forms import ClearableFileInput, ImageField as DjangoImageField from django.utils import timezone @@ -443,12 +441,10 @@ class ImageField(ActivitypubFieldMixin, models.ImageField): except ValidationError: return None - response = get_image(url) - if not response: + image_content, extension = get_image(url) + if not image_content: return None - image_content = ContentFile(response.content) - extension = imghdr.what(None, image_content.read()) or "" image_name = f"{uuid4()}.{extension}" return [image_name, image_content] diff --git a/bookwyrm/models/list.py b/bookwyrm/models/list.py index 7dff7214..ea524cc5 100644 --- a/bookwyrm/models/list.py +++ b/bookwyrm/models/list.py @@ -142,7 +142,7 @@ class ListItem(CollectionItemMixin, BookWyrmModel): user = fields.ForeignKey( "User", on_delete=models.PROTECT, activitypub_field="actor" ) - notes = fields.TextField(blank=True, null=True, max_length=300) + notes = fields.HtmlField(blank=True, null=True, max_length=300) approved = models.BooleanField(default=True) order = fields.IntegerField() endorsement = models.ManyToManyField("User", related_name="endorsers") diff --git a/bookwyrm/preview_images.py b/bookwyrm/preview_images.py index a97ae2d5..891c8b6d 100644 --- a/bookwyrm/preview_images.py +++ b/bookwyrm/preview_images.py @@ -4,6 +4,7 @@ import os import textwrap from io import BytesIO from uuid import uuid4 +import logging import colorsys from colorthief import ColorThief @@ -17,34 +18,49 @@ from django.db.models import Avg from bookwyrm import models, settings from bookwyrm.tasks import app +logger = logging.getLogger(__name__) IMG_WIDTH = settings.PREVIEW_IMG_WIDTH IMG_HEIGHT = settings.PREVIEW_IMG_HEIGHT BG_COLOR = settings.PREVIEW_BG_COLOR TEXT_COLOR = settings.PREVIEW_TEXT_COLOR DEFAULT_COVER_COLOR = settings.PREVIEW_DEFAULT_COVER_COLOR +DEFAULT_FONT = settings.PREVIEW_DEFAULT_FONT TRANSPARENT_COLOR = (0, 0, 0, 0) margin = math.floor(IMG_HEIGHT / 10) gutter = math.floor(margin / 2) inner_img_height = math.floor(IMG_HEIGHT * 0.8) inner_img_width = math.floor(inner_img_height * 0.7) -font_dir = os.path.join(settings.STATIC_ROOT, "fonts/public_sans") -def get_font(font_name, size=28): - """Loads custom font""" - if font_name == "light": - font_path = os.path.join(font_dir, "PublicSans-Light.ttf") - if font_name == "regular": - font_path = os.path.join(font_dir, "PublicSans-Regular.ttf") - elif font_name == "bold": - font_path = os.path.join(font_dir, "PublicSans-Bold.ttf") +def get_imagefont(name, size): + """Loads an ImageFont based on config""" + try: + config = settings.FONTS[name] + path = os.path.join(settings.FONT_DIR, config["directory"], config["filename"]) + return ImageFont.truetype(path, size) + except KeyError: + logger.error("Font %s not found in config", name) + except OSError: + logger.error("Could not load font %s from file", name) + + return ImageFont.load_default() + + +def get_font(weight, size=28): + """Gets a custom font with the given weight and size""" + font = get_imagefont(DEFAULT_FONT, size) try: - font = ImageFont.truetype(font_path, size) - except OSError: - font = ImageFont.load_default() + if weight == "light": + font.set_variation_by_name("Light") + if weight == "bold": + font.set_variation_by_name("Bold") + if weight == "regular": + font.set_variation_by_name("Regular") + except AttributeError: + pass return font diff --git a/bookwyrm/sanitize_html.py b/bookwyrm/sanitize_html.py index 8b0e3c4c..4edd2818 100644 --- a/bookwyrm/sanitize_html.py +++ b/bookwyrm/sanitize_html.py @@ -22,6 +22,7 @@ class InputHtmlParser(HTMLParser): # pylint: disable=abstract-method "ol", "li", ] + self.allowed_attrs = ["href", "rel", "src", "alt"] self.tag_stack = [] self.output = [] # if the html appears invalid, we just won't allow any at all @@ -30,7 +31,14 @@ class InputHtmlParser(HTMLParser): # pylint: disable=abstract-method def handle_starttag(self, tag, attrs): """check if the tag is valid""" if self.allow_html and tag in self.allowed_tags: - self.output.append(("tag", self.get_starttag_text())) + allowed_attrs = " ".join( + f'{a}="{v}"' for a, v in attrs if a in self.allowed_attrs + ) + reconstructed = f"<{tag}" + if allowed_attrs: + reconstructed += " " + allowed_attrs + reconstructed += ">" + self.output.append(("tag", reconstructed)) self.tag_stack.append(tag) else: self.output.append(("data", "")) diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index 8c4e8a7e..41e15922 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -9,7 +9,7 @@ from django.utils.translation import gettext_lazy as _ env = Env() env.read_env() DOMAIN = env("DOMAIN") -VERSION = "0.2.0" +VERSION = "0.3.0" PAGE_LENGTH = env("PAGE_LENGTH", 15) DEFAULT_LANGUAGE = env("DEFAULT_LANGUAGE", "English") @@ -35,6 +35,9 @@ LOCALE_PATHS = [ ] LANGUAGE_COOKIE_NAME = env.str("LANGUAGE_COOKIE_NAME", "django_language") +STATIC_ROOT = os.path.join(BASE_DIR, env("STATIC_ROOT", "static")) +MEDIA_ROOT = os.path.join(BASE_DIR, env("MEDIA_ROOT", "images")) + DEFAULT_AUTO_FIELD = "django.db.models.AutoField" # Preview image @@ -44,6 +47,17 @@ PREVIEW_TEXT_COLOR = env.str("PREVIEW_TEXT_COLOR", "#363636") PREVIEW_IMG_WIDTH = env.int("PREVIEW_IMG_WIDTH", 1200) PREVIEW_IMG_HEIGHT = env.int("PREVIEW_IMG_HEIGHT", 630) PREVIEW_DEFAULT_COVER_COLOR = env.str("PREVIEW_DEFAULT_COVER_COLOR", "#002549") +PREVIEW_DEFAULT_FONT = env.str("PREVIEW_DEFAULT_FONT", "Source Han Sans") + +FONTS = { + # pylint: disable=line-too-long + "Source Han Sans": { + "directory": "source_han_sans", + "filename": "SourceHanSans-VF.ttf.ttc", + "url": "https://github.com/adobe-fonts/source-han-sans/raw/release/Variable/OTC/SourceHanSans-VF.ttf.ttc", + } +} +FONT_DIR = os.path.join(STATIC_ROOT, "fonts") # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/ @@ -150,6 +164,9 @@ LOGGING = { "handlers": ["console", "mail_admins"], "level": LOG_LEVEL, }, + "django.utils.autoreload": { + "level": "INFO", + }, # Add a bookwyrm-specific logger "bookwyrm": { "handlers": ["console"], @@ -255,7 +272,7 @@ LANGUAGES = [ ("no-no", _("Norsk (Norwegian)")), ("pt-br", _("Português do Brasil (Brazilian Portuguese)")), ("pt-pt", _("Português Europeu (European Portuguese)")), - ("sv-se", _("Swedish (Svenska)")), + ("sv-se", _("Svenska (Swedish)")), ("zh-hans", _("简体中文 (Simplified Chinese)")), ("zh-hant", _("繁體中文 (Traditional Chinese)")), ] @@ -311,13 +328,12 @@ if USE_S3: MEDIA_FULL_URL = MEDIA_URL STATIC_FULL_URL = STATIC_URL DEFAULT_FILE_STORAGE = "bookwyrm.storage_backends.ImagesStorage" - # I don't know if it's used, but the site crashes without it - STATIC_ROOT = os.path.join(BASE_DIR, env("STATIC_ROOT", "static")) - MEDIA_ROOT = os.path.join(BASE_DIR, env("MEDIA_ROOT", "images")) else: STATIC_URL = "/static/" - STATIC_ROOT = os.path.join(BASE_DIR, env("STATIC_ROOT", "static")) MEDIA_URL = "/images/" MEDIA_FULL_URL = f"{PROTOCOL}://{DOMAIN}{MEDIA_URL}" STATIC_FULL_URL = f"{PROTOCOL}://{DOMAIN}{STATIC_URL}" - MEDIA_ROOT = os.path.join(BASE_DIR, env("MEDIA_ROOT", "images")) + +OTEL_EXPORTER_OTLP_ENDPOINT = env("OTEL_EXPORTER_OTLP_ENDPOINT", None) +OTEL_EXPORTER_OTLP_HEADERS = env("OTEL_EXPORTER_OTLP_HEADERS", None) +OTEL_SERVICE_NAME = env("OTEL_SERVICE_NAME", None) diff --git a/bookwyrm/static/css/bookwyrm.css b/bookwyrm/static/css/bookwyrm.css index f05ea3c9..ed03aa7b 100644 --- a/bookwyrm/static/css/bookwyrm.css +++ b/bookwyrm/static/css/bookwyrm.css @@ -319,7 +319,7 @@ details.details-panel summary { position: relative; } -details.details-panel summary .details-close { +details summary .details-close { position: absolute; right: 0; top: 0; @@ -327,7 +327,7 @@ details.details-panel summary .details-close { transition: transform 0.2s ease; } -details[open].details-panel summary .details-close { +details[open] summary .details-close { transform: rotate(0deg); } @@ -496,7 +496,7 @@ details[open].details-panel summary .details-close { max-height: 100%; /* Useful when stretching under-sized images. */ - image-rendering: optimizeQuality; + image-rendering: optimizequality; image-rendering: smooth; } diff --git a/bookwyrm/static/fonts/source_han_sans/LICENSE.txt b/bookwyrm/static/fonts/source_han_sans/LICENSE.txt new file mode 100644 index 00000000..ddf7b7e9 --- /dev/null +++ b/bookwyrm/static/fonts/source_han_sans/LICENSE.txt @@ -0,0 +1,96 @@ +Copyright 2014-2021 Adobe (http://www.adobe.com/), with Reserved Font +Name 'Source'. Source is a trademark of Adobe in the United States +and/or other countries. + +This Font Software is licensed under the SIL Open Font License, +Version 1.1. + +This license is copied below, and is also available with a FAQ at: +http://scripts.sil.org/OFL + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font +creation efforts of academic and linguistic communities, and to +provide a free and open framework in which fonts may be shared and +improved in partnership with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply to +any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software +components as distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, +deleting, or substituting -- in part or in whole -- any of the +components of the Original Version, by changing formats or by porting +the Font Software to a new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, +modify, redistribute, and sell modified and unmodified copies of the +Font Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, in +Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the +corresponding Copyright Holder. This restriction only applies to the +primary font name as presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created using +the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/bookwyrm/static/fonts/source_han_sans/README.txt b/bookwyrm/static/fonts/source_han_sans/README.txt new file mode 100644 index 00000000..53cfa9b8 --- /dev/null +++ b/bookwyrm/static/fonts/source_han_sans/README.txt @@ -0,0 +1,9 @@ +The font file itself is not included in the Git repository to avoid putting +large files in the repo history. The Docker image should download the correct +font into this folder automatically. + +In case something goes wrong, the font used is the Variable OTC TTF, available +as of this writing from the Adobe Fonts GitHub repository: +https://github.com/adobe-fonts/source-han-sans/tree/release#user-content-variable-otcs + +BookWyrm expects the file to be in this folder, named SourceHanSans-VF.ttf.ttc diff --git a/bookwyrm/telemetry/open_telemetry.py b/bookwyrm/telemetry/open_telemetry.py new file mode 100644 index 00000000..0b38a04b --- /dev/null +++ b/bookwyrm/telemetry/open_telemetry.py @@ -0,0 +1,22 @@ +from opentelemetry import trace +from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter +from opentelemetry.sdk.trace import TracerProvider +from opentelemetry.sdk.trace.export import BatchSpanProcessor + +trace.set_tracer_provider(TracerProvider()) +trace.get_tracer_provider().add_span_processor(BatchSpanProcessor(OTLPSpanExporter())) + + +def instrumentDjango(): + from opentelemetry.instrumentation.django import DjangoInstrumentor + + DjangoInstrumentor().instrument() + + +def instrumentCelery(): + from opentelemetry.instrumentation.celery import CeleryInstrumentor + from celery.signals import worker_process_init + + @worker_process_init.connect(weak=False) + def init_celery_tracing(*args, **kwargs): + CeleryInstrumentor().instrument() diff --git a/bookwyrm/templates/about/about.html b/bookwyrm/templates/about/about.html index 4e533b11..6f16aa67 100644 --- a/bookwyrm/templates/about/about.html +++ b/bookwyrm/templates/about/about.html @@ -28,7 +28,7 @@