11export const baseURL = "https://cms.chrisjogos.com" ;
22
3- const baseQuery = "fields=*,translations.*,tags.tags_id,tags_translations.*,card_image.id,card_image.type,genres.genres_id,steam_id,trailer_url,web_version_url,screenshots.directus_files_id.id,screenshots.directus_files_id.type" ;
3+ const baseQuery = "fields=*,translations.*,tags.tags_id,tags_translations.*,card_image.id,card_image.type,genres.genres_id,steam_id,trailer_url,web_version_url,screenshots.directus_files_id.id,screenshots.directus_files_id.type,related_posts.post_id.id,related_posts.post_id.title,related_posts.post_id.date_published,related_posts.post_id.cover_image.id,related_posts.post_id.cover_image.type,related_posts.post_id.status " ;
44
55const filter = import . meta. env . DEV
66 ? "filter[status][_in]=published,draft"
@@ -11,41 +11,56 @@ export const fieldsQuery = `${baseQuery}&${filter}`;
1111const DEFAULT_IMAGE_WIDTH = 800 ;
1212
1313/**
14- * Retorna a URL otimizada de um asset do Directus, aplicando WEBP e limite de largura por padrão .
15- * @param {string } id ID do asset .
16- * @param {number } [width=800] Largura máxima .
17- * @param {string } [options=''] Parâmetros adicionais (ex: 'height=120&fit=cover').
18- * @param {string } [mimeType=''] O MIME type do arquivo (ex: 'image/gif').
19- * @returns {string | null } URL otimizada .
14+ * Returns an optimized asset URL from Directus, applying WEBP format and width limit by default .
15+ * @param {string } id Asset ID .
16+ * @param {number } [width=800] Maximum width .
17+ * @param {string } [options=''] Additional parameters (e.g., 'height=120&fit=cover').
18+ * @param {string } [mimeType=''] The file MIME type (e.g., 'image/gif').
19+ * @returns {string | null } Optimized URL .
2020 */
2121export const getAssetUrl = ( id , width = DEFAULT_IMAGE_WIDTH , options = '' , mimeType = '' ) => {
2222 if ( ! id ) return null ;
23-
24- // Se for GIF, retorna a URL original sem otimização
23+
24+ // If it's a GIF, return the original URL without optimization
2525 if ( mimeType . toLowerCase ( ) === 'image/gif' ) {
2626 return `${ baseURL } /assets/${ id } ` ;
2727 }
28-
28+
2929 let params = `?format=webp&width=${ width } ` ;
3030 if ( options ) {
3131 params += `&${ options } ` ;
3232 }
33-
33+
3434 return `${ baseURL } /assets/${ id } ${ params } ` ;
3535} ;
3636
37+ /**
38+ * Formats a date string to a readable format.
39+ * @param {string } dateString Date string to format.
40+ * @returns {string } Formatted date.
41+ */
42+ export const formatDate = ( dateString ) => {
43+ if ( ! dateString ) return '' ;
44+ const date = new Date ( dateString ) ;
45+ return date . toLocaleDateString ( 'en-US' , {
46+ year : 'numeric' ,
47+ month : 'long' ,
48+ day : 'numeric'
49+ } ) ;
50+ }
51+
3752export function getHashedColor ( tagString ) {
3853 let hash = 0 ;
3954 if ( tagString . length === 0 ) return 'hsl(0, 0%, 30%)' ;
4055
4156 for ( let i = 0 ; i < tagString . length ; i ++ ) {
4257 const char = tagString . charCodeAt ( i ) ;
4358 hash = ( hash << 5 ) - hash + char ;
44- hash = hash & hash ; // Converte para 32bit integer
59+ hash = hash & hash ; // Convert to 32bit integer
4560 }
46-
61+
4762 const hue = Math . abs ( hash ) % 360 ;
48- // Usamos 60% de saturação e 35% de luminosidade
49- // É uma cor escura, mas colorida, perfeita para texto claro por cima
63+ // Use 60% saturation and 35% lightness
64+ // It's a dark but colorful color, perfect for light text on top
5065 return `hsl(${ hue } , 60%, 35%)` ;
5166}
0 commit comments