Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ site/errors/*.html
site/datetime/*.html
site/security/*.html
site/tooling/*.html
site/enterprise/*.html

# Generated aggregate file (built from individual JSON sources by html-generators/)
site/data/snippets.json
Expand Down
11 changes: 11 additions & 0 deletions html-generators/categories.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
language=Language
collections=Collections
strings=Strings
streams=Streams
concurrency=Concurrency
io=I/O
errors=Errors
datetime=Date/Time
security=Security
tooling=Tooling
enterprise=Enterprise
24 changes: 17 additions & 7 deletions html-generators/generate.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,23 @@
static final Pattern TOKEN = Pattern.compile("\\{\\{(\\w+)}}");
static final ObjectMapper MAPPER = new ObjectMapper();

static final SequencedMap<String, String> CATEGORY_DISPLAY = new LinkedHashMap<>() {{
put("language", "Language"); put("collections", "Collections");
put("strings", "Strings"); put("streams", "Streams");
put("concurrency", "Concurrency"); put("io", "I/O");
put("errors", "Errors"); put("datetime", "Date/Time");
put("security", "Security"); put("tooling", "Tooling");
}};
static final String CATEGORIES_FILE = "html-generators/categories.properties";
static final SequencedMap<String, String> CATEGORY_DISPLAY = loadCategoryDisplay();

static SequencedMap<String, String> loadCategoryDisplay() {
try {
var map = new LinkedHashMap<String, String>();
for (var line : Files.readAllLines(Path.of(CATEGORIES_FILE))) {
line = line.strip();
if (line.isEmpty() || line.startsWith("#")) continue;
var idx = line.indexOf('=');
if (idx > 0) map.put(line.substring(0, idx).strip(), line.substring(idx + 1).strip());
}
return map;
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

static final Set<String> EXCLUDED_KEYS = Set.of("_path", "prev", "next", "related");

Expand Down
38 changes: 20 additions & 18 deletions html-generators/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,25 @@
CONTENT_DIR = "content"
SITE_DIR = "site"

CATEGORY_DISPLAY = {
"language": "Language",
"collections": "Collections",
"strings": "Strings",
"streams": "Streams",
"concurrency": "Concurrency",
"io": "I/O",
"errors": "Errors",
"datetime": "Date/Time",
"security": "Security",
"tooling": "Tooling",
"enterprise": "Enterprise",
}
CATEGORIES_FILE = "html-generators/categories.properties"


def load_category_display():
"""Load category display names from the properties file."""
categories = {}
with open(CATEGORIES_FILE) as f:
for line in f:
line = line.strip()
if not line or line.startswith('#'):
continue
key, sep, value = line.partition('=')
key, value = key.strip(), value.strip()
if sep and key:
categories[key] = value
return categories


CATEGORY_DISPLAY = load_category_display()


def escape(text):
Expand Down Expand Up @@ -65,12 +71,8 @@ def load_template():
def load_all_snippets():
"""Load all JSON snippet files, keyed by category/slug."""
snippets = {}
categories = [
"language", "collections", "strings", "streams", "concurrency",
"io", "errors", "datetime", "security", "tooling", "enterprise",
]
json_files = []
for cat in categories:
for cat in CATEGORY_DISPLAY:
json_files.extend(sorted(glob.glob(f"{CONTENT_DIR}/{cat}/*.json")))
for path in json_files:
with open(path) as f:
Expand Down
Loading