Use static content mapping JSON file from the env

- Addes `STATIC_CONTENT_MAPPING` environment mapping that defaults to
  the current `stage_static_config.json`

- Fixes #725
This commit is contained in:
Frank Wiles
2023-10-27 08:22:27 -05:00
parent f91c80b1d7
commit 6d68f294c6
2 changed files with 17 additions and 8 deletions

View File

@@ -394,6 +394,11 @@ STATIC_CONTENT_AWS_S3_ENDPOINT_URL = env(
"STATIC_CONTENT_AWS_S3_ENDPOINT_URL", default="https://s3.us-east-2.amazonaws.com"
)
# JSON configuration of how we map static content in the S3 buckets to URL paths
STATIC_CONTENT_MAPPING = env(
"STATIC_CONTENT_MAPPING", default="stage_static_config.json"
)
# Markdown content
BASE_CONTENT = env("BOOST_CONTENT_DIRECTORY", "/website")

View File

@@ -1,19 +1,19 @@
import boto3
from botocore.exceptions import ClientError
from bs4 import BeautifulSoup, Tag
import json
import os
import re
import boto3
import structlog
from botocore.exceptions import ClientError
from bs4 import BeautifulSoup, Tag
from django.conf import settings
from mistletoe import HTMLRenderer
from mistletoe.span_token import SpanToken
from pygments import highlight
from pygments.styles import get_style_by_name as get_style
from pygments.lexers import get_lexer_by_name as get_lexer, guess_lexer
from pygments.formatters.html import HtmlFormatter
from pygments.lexers import get_lexer_by_name as get_lexer
from pygments.lexers import guess_lexer
from pygments.styles import get_style_by_name as get_style
logger = structlog.get_logger()
@@ -135,10 +135,14 @@ def get_s3_client():
)
def get_s3_keys(content_path, config_filename="stage_static_config.json"):
def get_s3_keys(content_path, config_filename=None):
"""
Get the S3 key for a given content path
"""
# Get configuration from settings if not specifically given
if config_filename is None:
config_filename = settings.STATIC_CONTENT_MAPPING
# Get the config file for the static content URL settings.
project_root = settings.BASE_DIR
config_file_path = os.path.join(project_root, config_filename)