Rustelo/resources/nickel/content/defaults.ncl

200 lines
5.5 KiB
Text
Raw Normal View History

2026-07-18 20:16:16 +01:00
# Content Types Configuration Defaults and Helpers
#
# Provides shared default values and helper functions for content type creation.
# Reduces duplication by providing common patterns.
let contracts = import "contracts.ncl" in
{
# Base content features with sensible defaults
# Use this as foundation via merge operator (&)
# Note: | default = allows overriding via merge
base_features = {
style_mode | default = "row",
use_feature | default = false,
use_categories | default = true,
use_tags | default = true,
use_emojis | default = false,
default_page_size | default = 12,
page_size_options | default = [6, 12, 24],
show_page_info | default = true,
pagination_style | default = "numbered",
},
# Base content kind with common defaults
base_content_kind = {
enabled | default = true,
is_default | default = false,
specialized | default = false,
},
# Helper function: Create a basic content type with minimal required fields
#
# Usage:
# make_content_kind "blog" "blog"
# & { features = { style_css = "blog-content", cta_view = "BlogCTAView" } }
#
# Parameters:
# kind_name: Content type name (e.g., "blog", "recipes")
# dir_name: Directory name where content is stored
#
# Returns: ContentKind record with defaults + required fields
make_content_kind
| String -> String -> Dyn
= fun kind_name dir_name =>
base_content_kind & {
name = kind_name,
directory = dir_name,
features = base_features & {
style_css | default = "%{kind_name}-content",
cta_view | default = "DefaultCTAView",
},
},
# Helper function: Create a blog-style content type
#
# Blog characteristics:
# - Row layout
# - Featured content
# - Categories and tags
# - Emojis enabled
# - Smaller page sizes
#
# Usage:
# make_blog_type "blog" "blog" "BlogCTAView"
#
# Parameters:
# kind_name: Content type name
# dir_name: Directory name
# cta_view_name: CTA view component name
#
# Returns: ContentKind configured for blog-style content
make_blog_type
| String -> String -> String -> Dyn
= fun kind_name dir_name cta_view_name =>
make_content_kind kind_name dir_name & {
features = base_features & {
style_mode = "row",
style_css = "%{kind_name}-content",
use_feature = true,
use_emojis = true,
cta_view = cta_view_name,
default_page_size = 8,
page_size_options = [5, 8, 12, 20],
},
},
# Helper function: Create a grid-style content type (recipes, portfolio, etc.)
#
# Grid characteristics:
# - Grid layout
# - No featured content typically
# - Categories (may or may not use tags)
# - Larger page sizes
#
# Usage:
# make_grid_type "recipes" "recipes" "RecipesCTAView"
# & { features.use_emojis = true }
#
# Parameters:
# kind_name: Content type name
# dir_name: Directory name
# cta_view_name: CTA view component name
#
# Returns: ContentKind configured for grid-style content
make_grid_type
| String -> String -> String -> Dyn
= fun kind_name dir_name cta_view_name =>
make_content_kind kind_name dir_name & {
features = base_features & {
style_mode = "grid",
style_css = "%{kind_name}-content",
use_feature | default = false,
cta_view = cta_view_name,
default_page_size = 12,
page_size_options = [6, 12, 18, 24],
},
},
# Helper function: Create a tutorial/course content type
#
# Tutorial characteristics:
# - Row layout
# - Featured content
# - Shows difficulty, duration, prerequisites
# - Categories and tags
#
# Usage:
# make_tutorial_type "tutorials" "tutorials" "TutorialsCTAView"
#
# Parameters:
# kind_name: Content type name
# dir_name: Directory name
# cta_view_name: CTA view component name
#
# Returns: ContentKind configured for tutorial content
make_tutorial_type
| String -> String -> String -> Dyn
= fun kind_name dir_name cta_view_name =>
make_content_kind kind_name dir_name & {
specialized = true,
features = base_features & {
style_mode = "row",
style_css = "%{kind_name}-content",
use_feature = true,
cta_view = cta_view_name,
show_difficulty = true,
show_duration = true,
show_prerequisites = true,
},
},
# Helper function: Create the default/fallback content type
#
# Default content type is used when no specific type matches.
# Typically has minimal features enabled.
#
# Usage:
# make_default_content "content" "content"
#
# Parameters:
# kind_name: Content type name (usually "content")
# dir_name: Directory name
#
# Returns: ContentKind configured as default type
make_default_content
| String -> String -> Dyn
= fun kind_name dir_name =>
make_content_kind kind_name dir_name & {
is_default = true,
features = base_features & {
style_css = "default-content",
cta_view = "DefaultCTAView",
},
},
# Common style modes
style_modes = {
row = "row",
grid = "grid",
masonry = "masonry",
list = "list",
},
# Common pagination styles
pagination_styles = {
numbered = "numbered",
simple = "simple",
infinite = "infinite",
load_more = "load_more",
},
# Common page size presets
page_sizes = {
small = [5, 10, 15, 20],
medium = [8, 12, 20, 30],
large = [12, 24, 36, 48],
cards = [6, 12, 18, 24],
},
}