config | lib works
This commit is contained in:
parent
ca79656a90
commit
bdf641baab
@ -1,12 +1,12 @@
|
||||
export default {
|
||||
"environment": "dev",
|
||||
"environment": "build",
|
||||
"isSsrBuild": false,
|
||||
"projectBase": "",
|
||||
"publicDir": "C:\\Users\\zx\\Desktop\\polymech\\site2\\public\\",
|
||||
"rootDir": "C:\\Users\\zx\\Desktop\\polymech\\site2\\",
|
||||
"mode": "dev",
|
||||
"outDir": "dist",
|
||||
"assetsDir": "/_astro",
|
||||
"mode": "production",
|
||||
"outDir": "C:\\Users\\zx\\Desktop\\polymech\\site2\\dist\\",
|
||||
"assetsDir": "_astro",
|
||||
"sourcemap": false,
|
||||
"assetFileNames": "/_astro/[name]@[width].[hash][extname]"
|
||||
}
|
||||
@ -4,9 +4,7 @@ import path from "node:path";
|
||||
import findCacheDir from "find-cache-dir";
|
||||
import filterConfigs from "./filterConfigs.js";
|
||||
import { findUpSync } from "find-up"
|
||||
|
||||
import { cache_path } from "@polymech/cache"
|
||||
import { get_var, DEFAULT_ROOTS } from "@polymech/commons/config"
|
||||
import { get_var } from "@polymech/commons/config"
|
||||
import { resolve } from "@polymech/commons"
|
||||
import { sync as mkdir } from "@polymech/fs/dir"
|
||||
import { sync as exists } from "@polymech/fs/exists"
|
||||
|
||||
@ -1,11 +0,0 @@
|
||||
|
||||
import { loadConfig } from '../src/app/config-loader.js';
|
||||
import { I18N_SOURCE_LANGUAGE } from "../src/app/constants.js";
|
||||
|
||||
try {
|
||||
const config = loadConfig(I18N_SOURCE_LANGUAGE);
|
||||
console.log('LOGGING_NAMESPACE:', config.core.logging_namespace);
|
||||
console.log('SHOW_GALLERY:', config.features.show_gallery);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
@ -41,11 +41,18 @@ function deepMerge(target: any, source: any): any {
|
||||
return result;
|
||||
}
|
||||
|
||||
const configCache = new Map<string, AppConfig>();
|
||||
|
||||
export function loadConfig(
|
||||
locale: string = I18N_SOURCE_LANGUAGE,
|
||||
config: string = LIBRARY_CONFIG_PATH,
|
||||
schema: z.ZodType<any> = appConfigSchema,
|
||||
): AppConfig {
|
||||
const cacheKey = `${locale}:${config}`;
|
||||
if (configCache.has(cacheKey)) {
|
||||
return configCache.get(cacheKey)!;
|
||||
}
|
||||
|
||||
// 1. Load Library Config (Defaults)
|
||||
let rawLibraryContent: string;
|
||||
try {
|
||||
@ -98,6 +105,6 @@ export function loadConfig(
|
||||
|
||||
// @todo 6. Validate
|
||||
// const result = schema.parse(mergedConfig);
|
||||
write('./app-c2.json', JSON.stringify(mergedConfig));
|
||||
configCache.set(cacheKey, mergedConfig);
|
||||
return mergedConfig;
|
||||
}
|
||||
|
||||
@ -1,14 +1,16 @@
|
||||
import * as path from 'path'
|
||||
|
||||
export const I18N_SOURCE_LANGUAGE = 'en'
|
||||
|
||||
import { IMAGE_PRESET, E_BROADBAND_SPEED } from "./network.js"
|
||||
import { resolve, template } from '@polymech/commons'
|
||||
import { sync as read } from '@polymech/fs/read'
|
||||
import { sanitizeUri } from 'micromark-util-sanitize-uri'
|
||||
import { loadConfig } from './config-loader.js'
|
||||
|
||||
export const I18N_SOURCE_LANGUAGE = 'en'
|
||||
|
||||
// Load config
|
||||
const config = loadConfig(I18N_SOURCE_LANGUAGE)
|
||||
const config = loadConfig()
|
||||
|
||||
export const OSR_ROOT = () => path.resolve(resolve(config.core.osr_root))
|
||||
export const FILE_SERVER_DEV = config.dev.file_server
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
import { z } from "zod"
|
||||
import { loadConfig } from './config-loader.js'
|
||||
const config = loadConfig()
|
||||
/////////////////////////////////////////////
|
||||
//
|
||||
// Optimizations
|
||||
@ -24,11 +26,9 @@ const imagesSchema = z.object({
|
||||
|
||||
type Images = z.infer<typeof imagesSchema>;
|
||||
|
||||
import { loadConfig } from './config-loader.js'
|
||||
import { I18N_SOURCE_LANGUAGE } from "./config.js"
|
||||
|
||||
// Load config
|
||||
const config = loadConfig(I18N_SOURCE_LANGUAGE)
|
||||
|
||||
|
||||
|
||||
export const IMAGE_PRESET: Images =
|
||||
{
|
||||
|
||||
@ -34,17 +34,7 @@ export const render = async (string) => {
|
||||
const html = `${unescapeHTML(string)}`
|
||||
return createComponent(() => renderTemplate(html as any, []))
|
||||
}
|
||||
/*
|
||||
export const component = async (str: string = "", locale, data = {}) => {
|
||||
const content = await translate(
|
||||
(str || "").trim(),
|
||||
I18N_SOURCE_LANGUAGE,
|
||||
locale
|
||||
)
|
||||
const markup = ((await renderMarkup(content, data)) as any) || { html: "" }
|
||||
return await render(markup.html)
|
||||
}
|
||||
*/
|
||||
|
||||
export const item_defaults = async (itemDir) => {
|
||||
return await findUp('defaults.json', {
|
||||
stopAt: PRODUCT_ROOT(),
|
||||
|
||||
@ -3,7 +3,7 @@ import { Img } from "imagetools/components";
|
||||
|
||||
import { globBase, pathInfo } from "@polymech/commons";
|
||||
import Translate from "./i18n.astro";
|
||||
import { IMAGE_SETTINGS } from "../app/config.js";
|
||||
import { IMAGE_SETTINGS } from "../app/config.js";
|
||||
import path from "node:path";
|
||||
import { glob } from 'glob';
|
||||
import { extractImageMetadata, groupByYear, groupByMonth, GroupInfo } from "../base/media";
|
||||
@ -57,16 +57,16 @@ const {
|
||||
} = Astro.props;
|
||||
|
||||
const mergedGallerySettings = {
|
||||
SIZES_REGULAR: gallerySettings.SIZES_REGULAR || IMAGE_SETTINGS.GALLERY.SIZES_REGULAR,
|
||||
SIZES_THUMB: gallerySettings.SIZES_THUMB || IMAGE_SETTINGS.GALLERY.SIZES_THUMB,
|
||||
SHOW_TITLE: gallerySettings.SHOW_TITLE ?? IMAGE_SETTINGS.GALLERY.SHOW_TITLE,
|
||||
SHOW_DESCRIPTION: gallerySettings.SHOW_DESCRIPTION ?? IMAGE_SETTINGS.GALLERY.SHOW_DESCRIPTION,
|
||||
SIZES_REGULAR: gallerySettings.SIZES_REGULAR || IMAGE_SETTINGS.gallery.sizes_regular,
|
||||
SIZES_THUMB: gallerySettings.SIZES_THUMB || IMAGE_SETTINGS.gallery.sizes_thumb,
|
||||
SHOW_TITLE: gallerySettings.SHOW_TITLE ?? IMAGE_SETTINGS.gallery.show_title,
|
||||
SHOW_DESCRIPTION: gallerySettings.SHOW_DESCRIPTION ?? IMAGE_SETTINGS.gallery.show_description,
|
||||
};
|
||||
|
||||
const mergedLightboxSettings = {
|
||||
SIZES_LARGE: lightboxSettings.SIZES_LARGE || IMAGE_SETTINGS.LIGHTBOX.SIZES_LARGE,
|
||||
SHOW_TITLE: lightboxSettings.SHOW_TITLE ?? IMAGE_SETTINGS.LIGHTBOX.SHOW_TITLE,
|
||||
SHOW_DESCRIPTION: lightboxSettings.SHOW_DESCRIPTION ?? IMAGE_SETTINGS.LIGHTBOX.SHOW_DESCRIPTION,
|
||||
SIZES_LARGE: lightboxSettings.SIZES_LARGE || IMAGE_SETTINGS.lightbox.sizes_large,
|
||||
SHOW_TITLE: lightboxSettings.SHOW_TITLE ?? IMAGE_SETTINGS.lightbox.show_title,
|
||||
SHOW_DESCRIPTION: lightboxSettings.SHOW_DESCRIPTION ?? IMAGE_SETTINGS.lightbox.show_description,
|
||||
};
|
||||
|
||||
const locale = Astro.currentLocale || "en";
|
||||
|
||||
Loading…
Reference in New Issue
Block a user