From 9e72aca04cd2bf7b51152b647a443d945e16ec42 Mon Sep 17 00:00:00 2001 From: babayaga Date: Tue, 18 Mar 2025 18:53:54 +0100 Subject: [PATCH] site template cleanup 1/3 --- .astro/content-modules.mjs | 2 +- src/base/media.ts | 58 ++-- src/components/BaseHead.astro | 10 +- src/components/embed/youtube.astro | 131 --------- src/components/forms/Contact.astro | 140 ---------- .../head/ArticleStructuredData.astro | 1 - src/components/landing/Hero.astro | 11 - src/components/landing/HeroThree.astro | 13 - src/components/landing/HeroTwo.astro | 13 - .../{pricing => polymech}/PricingTiers.astro | 0 src/components/src/base/index.ts | 65 ----- src/components/src/components/BaseHead.astro | 21 -- src/components/system/StyleGuide.astro | 260 ------------------ src/config/config.json | 2 +- src/config/menu.json | 59 ---- src/images/logo.svg | 8 - src/model/component.ts | 44 +-- src/pages/pricing/pricing-full.astro | 11 - src/pages/system/styleguide.astro | 7 - src/pages/{software => tests}/overview.astro | 76 ++--- 20 files changed, 84 insertions(+), 848 deletions(-) delete mode 100644 src/components/embed/youtube.astro delete mode 100644 src/components/forms/Contact.astro delete mode 100644 src/components/landing/Hero.astro delete mode 100644 src/components/landing/HeroThree.astro delete mode 100644 src/components/landing/HeroTwo.astro rename src/components/{pricing => polymech}/PricingTiers.astro (100%) delete mode 100644 src/components/src/base/index.ts delete mode 100644 src/components/src/components/BaseHead.astro delete mode 100644 src/components/system/StyleGuide.astro delete mode 100644 src/config/menu.json delete mode 100644 src/images/logo.svg delete mode 100644 src/pages/pricing/pricing-full.astro delete mode 100644 src/pages/system/styleguide.astro rename src/pages/{software => tests}/overview.astro (97%) diff --git a/.astro/content-modules.mjs b/.astro/content-modules.mjs index cf5c600..bc36b6f 100644 --- a/.astro/content-modules.mjs +++ b/.astro/content-modules.mjs @@ -1,7 +1,7 @@ export default new Map([ -["src/content/infopages/community.mdx", () => import("astro:content-layer-deferred-module?astro%3Acontent-layer-deferred-module=&fileName=src%2Fcontent%2Finfopages%2Fcommunity.mdx&astroContentModuleFlag=true")], ["src/content/infopages/contact.mdx", () => import("astro:content-layer-deferred-module?astro%3Acontent-layer-deferred-module=&fileName=src%2Fcontent%2Finfopages%2Fcontact.mdx&astroContentModuleFlag=true")], +["src/content/infopages/community.mdx", () => import("astro:content-layer-deferred-module?astro%3Acontent-layer-deferred-module=&fileName=src%2Fcontent%2Finfopages%2Fcommunity.mdx&astroContentModuleFlag=true")], ["src/content/infopages/resources.mdx", () => import("astro:content-layer-deferred-module?astro%3Acontent-layer-deferred-module=&fileName=src%2Fcontent%2Finfopages%2Fresources.mdx&astroContentModuleFlag=true")], ["src/content/infopages/software.mdx", () => import("astro:content-layer-deferred-module?astro%3Acontent-layer-deferred-module=&fileName=src%2Fcontent%2Finfopages%2Fsoftware.mdx&astroContentModuleFlag=true")]]); \ No newline at end of file diff --git a/src/base/media.ts b/src/base/media.ts index 0593480..aca0c45 100644 --- a/src/base/media.ts +++ b/src/base/media.ts @@ -3,15 +3,15 @@ import pMap from 'p-map' import { GlobOptions } from 'glob' import { sanitizeUri } from 'micromark-util-sanitize-uri' import ExifReader from 'exifreader' - import { loadImage } from "imagetools/api" - +import { sanitizeFilename } from '@polymech/fs/utils' import { resolve } from '@polymech/commons' import { files } from '@polymech/commons' import { sync as exists } from '@polymech/fs/exists' import { sync as read } from '@polymech/fs/read' -import { sync as mv } from '@polymech/fs/move' import { logger } from '@/base/index.js' +import { env } from './index.js' +import { GalleryImage, MetaJSON } from './images.js' import { removeArrayValues, @@ -25,12 +25,8 @@ import { DEFAULT_IMAGE_URL, ASSETS_LOCAL, ASSETS_GLOB } from 'config/config.js' -import { GalleryImage, MetaJSON } from './images.js' - -import { validateFilename, sanitizeFilename } from "@polymech/fs/utils" - -import { env } from './index.js' +export const default_sanitizer = (files:string[]) => files.map((f) => sanitizeFilename(f)) export const default_sort = (files: string[]): string[] => { const getSortableParts = (filename: string) => { @@ -51,25 +47,6 @@ export const default_sort = (files: string[]): string[] => { }) } -export const default_sanitize = (paths: string[]): string[] => { - return paths.map((filePath) => { - const dir = path.dirname(filePath); - const originalFilename = path.basename(filePath); - const sanitizedFilename = sanitizeFilename(originalFilename) - if (originalFilename === sanitizedFilename) { - return filePath; - } - const newPath = path.join(dir, sanitizedFilename); - - try { - mv(filePath, newPath); - return newPath; - } catch (error) { - return filePath; // Return the original path in case of failure - } - }); -} - export const default_filter = async (url: string) => { try { const response = await fetch(url, { method: 'HEAD' }) @@ -103,25 +80,23 @@ export const image_url = async (src, fallback = DEFAULT_IMAGE_URL) => { return safeSrc } -export const gallery = async ( - assetPath, - product): Promise => { - product = '' + product +export const gallery = async ( assetPath, item): Promise => { + const root = resolve(PRODUCT_ROOT()) const profile = env() const assetSlug = path.parse(assetPath).name - const productConfig: any = read(PRODUCT_CONFIG(product), "json") - if (!productConfig) { - logger.warn(`item gallery : item ${product} config not found !`) + const itemConfig: any = read(PRODUCT_CONFIG(item), "json") + if (!itemConfig) { + logger.warn(`item gallery : item ${item} config not found !`) return [] } - const mediaPath = `${root}/${product}/${assetPath}/` + const mediaPath = `${root}/${item}/${assetPath}/` if (!exists(mediaPath)) { - logger.warn(`item gallery : item ${product} media path not found ${mediaPath}!`) + logger.warn(`item gallery : item ${item} media path not found ${mediaPath}!`) return [] } - const galleryGlob = (productConfig.gallery || {})[assetSlug]?.glob || ASSETS_GLOB + const galleryGlob = (itemConfig.gallery || {})[assetSlug]?.glob || ASSETS_GLOB let galleryFiles: any[] = files(mediaPath, galleryGlob, { cwd: mediaPath, absolute: false, @@ -133,7 +108,7 @@ export const gallery = async ( } if (!galleryFiles) { - logger.warn(`ProductGallery : Product ${product} media files not found ! ${mediaPath}`) + logger.warn(`gallery : ${item} media files not found ! ${mediaPath}`) return [] } const assetUrl = (filePath) => { @@ -141,20 +116,19 @@ export const gallery = async ( { assetPath, filePath, - ITEM_REL: product, + ITEM_REL: item, ...profile.variables } )) } - if (!ASSETS_LOCAL) { galleryFiles = await pMap(galleryFiles, async (f) => (await default_filter(assetUrl(f))) ? f : null, { concurrency: 5 }) galleryFiles = galleryFiles.filter((f) => f !== null) galleryFiles = default_sort(galleryFiles) } else { galleryFiles = galleryFiles.filter(default_filter_locale) - galleryFiles = default_sort(galleryFiles) - } + } + galleryFiles = default_sort(galleryFiles) return await pMap(galleryFiles, async (file: string) => { const parts = path.parse(file) diff --git a/src/components/BaseHead.astro b/src/components/BaseHead.astro index 89608fe..e1545a5 100644 --- a/src/components/BaseHead.astro +++ b/src/components/BaseHead.astro @@ -1,13 +1,13 @@ --- import "../styles/flowbite.css" +import "../styles/global.css" +import "../styles/custom.scss" import { LANGUAGES_PROD } from "config/config.js" import config from "@/config/config.json" -import { plainify } from "../base/strings.js" +import { plainify } from "@/base/strings.js" -import "../styles/global.css" -import "../styles/custom.scss" import { AstroSeo } from "@astrolib/seo" import { item_keywords } from '@/base/seo.js' @@ -55,7 +55,7 @@ const description = item?.description as string || config.metadata.description const keywords = await item_keywords(item, Astro.currentLocale) -const tracking = config?.tracking?.googleAnalytics +const tracking = config?.tracking?.googleAnalytics || 'G-RW6Q6EG3J0' --- )} diff --git a/src/components/embed/youtube.astro b/src/components/embed/youtube.astro deleted file mode 100644 index 1870a3a..0000000 --- a/src/components/embed/youtube.astro +++ /dev/null @@ -1,131 +0,0 @@ ---- -interface Props extends Omit { - /** - * Pass `true` to embed using `www.youtube.com` instead of `www.youtube-nocookie.com` - */ - cookie?: boolean - /** - * YouTube IFrame Player API parameters - * - * Defaults to `{autoplay: 1}`, additional parameters will be merged into the defaults - * @see https://developers.google.com/youtube/player_parameters#Parameters - */ - embedParams?: EmbedParams - /** - * `loading` attribute for the thumbnail `` - * - * Defaults to `"lazy"` - */ - loading?: 'eager' | 'lazy' - /** - * Pass `true` to omit the "Watch on YouTube" link - saves ~3.86 KB - */ - noLink?: boolean - /** - * Thumbnail image to use in the static embed - * - * Defaults to `"default"`, pass 1, 2 or 3 to use a screenshot from the video instead. - */ - thumbnail?: Thumbnail - /** - * Thumbnail resolution - * - * Defaults to `"sd"` (640x480) - */ - thumbnailRes?: ThumbnailRes - /** - * Title for the static embed - */ - title: string - /** - * 11-digit YouTube video id - */ - videoId: string -} - -interface EmbedParams { - autoplay?: ToggleParam - cc_lang_pref?: string - cc_load_policy?: ToggleParam - color?: 'red' | 'white' - controls?: ToggleParam - disablekb?: ToggleParam - enablejsapi?: ToggleParam - end?: number - fs?: ToggleParam - hl?: string - iv_load_policy?: 1 | '1' | 3 | '3' - list?: string - listType?: 'playlist' | 'user_uploads' - loop?: ToggleParam - /** @deprecated has no effect, deprecated by YouTube on August 15 2023 */ - modestbranding?: ToggleParam - origin?: string - playlist?: string - playslinline?: ToggleParam - rel?: ToggleParam - start?: number - widget_referrer?: string -} - -type ToggleParam = 0 | '0' | 1 | '1' - -type Thumbnail = 'default' | 1 | '1' | 2 | '2' | 3 | '3' | string - -type ThumbnailRes = 120 | '120' | 'default' | 320 | '320' | 'medium' | 'mq' | 480 | '480' | 'high' | 'hq' | 640 | '640' | 'standard' | 'sd' | 1280 | '1280' | 'maxres' - -const QUALITY_PREFIXES = { - 120: '', - default: '', - 320: 'mq', - medium: 'mq', - mq: 'mq', - 480: 'hq', - high: 'hq', - hq: 'hq', - 640: 'sd', - standard: 'sd', - sd: 'sd', - 1280: 'maxres', - maxres: 'maxres', -} - -let { - cookie = false, - embedParams, - loading = 'lazy', - noLink = false, - thumbnail = 'default', - thumbnailRes = 'sd', - title, - videoId, - ...iframeAttributes -} = Astro.props as Props - -let params: EmbedParams = {autoplay: 1, ...embedParams} - -let embedQuery = Object.keys(params).map(key => `${key}=${params[key]}`).join('&') -let embedUrl = `https://www.youtube${cookie ? '' : '-nocookie'}.com/embed${videoId ? `/${videoId}` : ''}${embedQuery ? `?${embedQuery}` : ''}` -let thumbnailUrl = !/^(default|1|2|3)$/.test(String(thumbnail)) ? thumbnail : `https://i.ytimg.com/vi/${videoId}/${QUALITY_PREFIXES[thumbnailRes]}${thumbnail}.jpg` - -let linkSvg = `` -let playButtonSvg = `` - -let gradientStyle = `.gradient{width:100%;height:49px;padding-bottom:50px;position:absolute;top:0;background-repeat:repeat-x;background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAADGCAYAAAAT+OqFAAAAdklEQVQoz42QQQ7AIAgEF/T/D+kbq/RWAlnQyyazA4aoAB4FsBSA/bFjuF1EOL7VbrIrBuusmrt4ZZORfb6ehbWdnRHEIiITaEUKa5EJqUakRSaEYBJSCY2dEstQY7AuxahwXFrvZmWl2rh4JZ07z9dLtesfNj5q0FU3A5ObbwAAAABJRU5ErkJggg==);pointer-events:none}` -let linkStyle = noLink ? '' : '.woyt{z-index:2;background:rgba(23,23,23,.8);border-bottom-right-radius:2px;border-top-right-radius:2px;bottom:5px;height:47px;position:absolute}.woyt-text{color:#fff;float:left;font:500 16px/16px "YouTube Noto",Roboto,Arial,Helvetica,sans-serif;margin-left:12px;margin-top:16px}.woyt-logo{float:right;height:16px;margin-left:9px;margin-right:12px;margin-top:16px;width:72px}' -let style = `` - -let link = noLink ? '' : `` -let srcdoc = `${style}${link}${title}
${title}
${playButtonSvg}
` ---- -