Something went wrong. Try again.
standard.site frontend
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283import 'dart:io';
import 'package:path/path.dart' as p;import 'package:yaml/yaml.dart';
/// Site configuration used by both the CLI and the server.class SiteConfig { final String handle; final String service; final String url; final String? publicationRkey;
SiteConfig({ required this.handle, required this.service, required this.url, this.publicationRkey, });
factory SiteConfig.fromYaml(String content) { final yaml = loadYaml(content); if (yaml is! Map) { throw const FormatException('Invalid site config: expected a map'); }
return SiteConfig( handle: yaml['handle'] as String, service: yaml['service'] as String, url: yaml['url'] as String, publicationRkey: yaml['publicationRkey'] as String?, ); }
String toYaml() { final buffer = StringBuffer() ..writeln('# Site configuration for vibecode.rodeo') ..writeln() ..writeln('handle: ${_escape(handle)}') ..writeln('service: ${_escape(service)}') ..writeln('url: ${_escape(url)}');
if (publicationRkey != null) { buffer.writeln('publicationRkey: ${_escape(publicationRkey!)}'); }
return buffer.toString(); }
static String _escape(String value) { if (value.contains(RegExp("[:#@\\s'\"]"))) { return '"${value.replaceAll('"', '\\"')}"'; } return value; }}
/// Loads site config from the config directory.SiteConfig loadSiteConfig([String? basePath]) { final file = File( p.join(basePath ?? Directory.current.path, 'config', 'site.yaml'), );
if (!file.existsSync()) { throw FileSystemException( 'Site config not found. Copy config/site.example.yaml to config/site.yaml and fill it in.', file.path, ); }
return SiteConfig.fromYaml(file.readAsStringSync());}
/// Saves site config to the config directory.void saveSiteConfig(SiteConfig config, [String? basePath]) { final dir = Directory(p.join(basePath ?? Directory.current.path, 'config')); if (!dir.existsSync()) { dir.createSync(recursive: true); }
final file = File(p.join(dir.path, 'site.yaml')); file.writeAsStringSync(config.toYaml());}