mirror of
https://github.com/sbrow/thor.git
synced 2026-08-26 11:23:32 -04:00
feat: Removed static dir from sites.
This commit is contained in:
+1
-43
@@ -217,47 +217,8 @@ strip_extension :: proc(name: string) -> string {
|
||||
return name[:dot]
|
||||
}
|
||||
|
||||
// copy_static_dir recursively copies all files from static_dir to output_dir.
|
||||
// Silently skips if static_dir doesn't exist.
|
||||
copy_static_dir :: proc(static_dir: string, output_dir: string) {
|
||||
if !os.exists(static_dir) {
|
||||
return
|
||||
}
|
||||
copy_static_recursive(static_dir, "", output_dir)
|
||||
}
|
||||
|
||||
copy_static_recursive :: proc(current: string, rel_prefix: string, output_dir: string) {
|
||||
entries, err := os.read_all_directory_by_path(current, context.allocator)
|
||||
if err != nil {
|
||||
log.warnf("thor: cannot read %s: %v", current, err)
|
||||
return
|
||||
}
|
||||
defer os.file_info_slice_delete(entries, context.allocator)
|
||||
|
||||
for entry in entries {
|
||||
rel := rel_prefix == "" ? entry.name : fmt.tprintf("%s/%s", rel_prefix, entry.name)
|
||||
switch entry.type {
|
||||
case .Regular:
|
||||
dest := fmt.tprintf("%s/%s", output_dir, rel)
|
||||
if idx := strings.last_index(dest, "/"); idx >= 0 {
|
||||
if err := os.make_directory_all(dest[:idx]); err != nil && err != .Exist {
|
||||
log.warnf("thor: cannot create %s: %v", dest[:idx], err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
if err := os.copy_file(dest, entry.fullpath); err != nil {
|
||||
log.warnf("thor: cannot copy %s: %v", entry.fullpath, err)
|
||||
}
|
||||
case .Directory:
|
||||
copy_static_recursive(entry.fullpath, rel, output_dir)
|
||||
case .Undetermined, .Symlink, .Named_Pipe, .Socket, .Block_Device, .Character_Device:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// copy_assets_dir recursively copies files from assets_dir to output_dir.
|
||||
// .css files are minified when .Minify is enabled; all other files are copied
|
||||
// verbatim with a warning suggesting they belong in static/.
|
||||
// .css files are minified when .Minify is enabled; all other files are copied verbatim.
|
||||
// Silently skips if assets_dir doesn't exist.
|
||||
copy_assets_dir :: proc(assets_dir: string, output_dir: string, features: bit_set[Feature]) {
|
||||
if !os.exists(assets_dir) {
|
||||
@@ -299,9 +260,6 @@ copy_assets_recursive :: proc(
|
||||
minified := minify_css(string(data))
|
||||
write_file(dest, minified)
|
||||
} else {
|
||||
if !strings.has_suffix(entry.name, ".css") {
|
||||
log.warnf("thor: %s is not a CSS file; consider moving it to static/", entry.fullpath)
|
||||
}
|
||||
if err := os.copy_file(dest, entry.fullpath); err != nil {
|
||||
log.warnf("thor: cannot copy %s: %v", entry.fullpath, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user