Source Code

/ src / repository / urls.py

from . import views
from django_distill import distill_path
from repository.models import File

def get_file_paths():
    """Get all non-directory files for static generation"""
    for f in File.objects.all():
        if not f.is_directory:
            yield {"file_path": f.path}

def get_directory_paths():
    """Get all directories for static generation"""
    for f in File.objects.all():
        if f.is_directory:
            yield {"file_path": f.path}

def get_root_path():
    """Get root path for static generation"""
    yield {}

urlpatterns = [
    distill_path(
        '',
        views.code_file_index,
        name='code_file_index',
        distill_func=get_root_path,
        distill_file='src/index.html',
    ),
    distill_path(
        '<path:file_path>/',
        views.code_file,
        name='code_file_dir',
        distill_func=get_directory_paths,
        distill_file="src/{file_path}/index.html"
    ),
    distill_path(
        '<path:file_path>',
        views.code_file,
        name='code_file',
        distill_func=get_file_paths,
        distill_file="src/{file_path}/index.html"
    ),
]