diff --git a/astro.config.mjs b/astro.config.mjs index 0409e02..3932dc4 100755 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -23,6 +23,11 @@ export default defineConfig({ site: config.site.base_url ? config.site.base_url : "http://examplesite.com", base: config.site.base_path ? config.site.base_path : "/", trailingSlash: config.site.trailing_slash ? "always" : "ignore", + output: "static", + build: { + format: 'directory', + assets: '_assets', + }, i18n: { locales: filteredSupportedLang, defaultLocale: default_language, @@ -31,7 +36,9 @@ export default defineConfig({ service: squooshImageService(), }, integrations: [ - react(), + react({ + include: ['**/Youtube.tsx', '**/*.tsx'], + }), sitemap(), tailwind({ applyBaseStyles: false, @@ -65,4 +72,22 @@ export default defineConfig({ }, extendDefaultPlugins: true, }, + vite: { + build: { + sourcemap: false, + minify: true, + rollupOptions: { + output: { + manualChunks: undefined, + }, + }, + }, + optimizeDeps: { + include: ['react-lite-youtube-embed'], + exclude: ['@astrojs/mdx'], + }, + ssr: { + noExternal: ['react-lite-youtube-embed'], + }, + }, }); diff --git a/netlify.toml b/netlify.toml index 4b04bea..9b42001 100755 --- a/netlify.toml +++ b/netlify.toml @@ -1,6 +1,25 @@ [build] -publish = "dist" -command = "yarn build" + command = "yarn install --frozen-lockfile && yarn generate-json && yarn build" + publish = "dist" [build.environment] NODE_VERSION = "20" +NODE_ENV = "production" +YARN_FLAGS = "--frozen-lockfile" +NETLIFY_USE_YARN = "true" + +[build.processing] + skip_processing = false + +[[redirects]] +from = "/*" +to = "/index.html" +status = 200 + +[[headers]] + for = "/*" + [headers.values] + X-Frame-Options = "DENY" + X-XSS-Protection = "1; mode=block" + X-Content-Type-Options = "nosniff" + Referrer-Policy = "strict-origin-when-cross-origin" \ No newline at end of file diff --git a/scripts/jsonGenerator.js b/scripts/jsonGenerator.js index 5881da2..b81214c 100644 --- a/scripts/jsonGenerator.js +++ b/scripts/jsonGenerator.js @@ -10,10 +10,20 @@ const BLOG_FOLDER = "blog"; // get data from markdown const getData = (folder, groupDepth, langIndex = 0) => { + console.log(`Processing folder: ${folder}`); + const getPaths = languages .map((lang, index) => { const langFolder = lang.contentDir ? lang.contentDir : lang.languageCode; const dir = path.join(CONTENT_ROOT, folder, langFolder); + + console.log(`Checking directory: ${dir}`); + + if (!fs.existsSync(dir)) { + console.warn(`Directory does not exist: ${dir}`); + return []; + } + return fs .readdirSync(dir) .filter( @@ -23,38 +33,45 @@ const getData = (folder, groupDepth, langIndex = 0) => { ) .flatMap((filename) => { const filepath = path.join(dir, filename); - const stats = fs.statSync(filepath); - const isFolder = stats.isDirectory(); + console.log(`Processing file: ${filepath}`); + + try { + const stats = fs.statSync(filepath); + const isFolder = stats.isDirectory(); - if (isFolder) { - return getData(filepath, groupDepth, index); - } else { - const file = fs.readFileSync(filepath, "utf-8"); - const { data, content } = matter(file); - const pathParts = filepath.split(path.sep); - - let slug; - if (data.slug) { - const slugParts = data.slug.split("/"); - slugParts[0] = BLOG_FOLDER; - slug = slugParts.join("/"); + if (isFolder) { + return getData(filepath, groupDepth, index); } else { - slug = pathParts - .slice(CONTENT_DEPTH) - .join("/") - .replace(/\.[^/.]+$/, ""); - slug = `${BLOG_FOLDER}/${slug.split("/").slice(1).join("/")}`; - } - data.slug = slug; - const group = "blog"; + const file = fs.readFileSync(filepath, "utf-8"); + const { data, content } = matter(file); + const pathParts = filepath.split(path.sep); + + let slug; + if (data.slug) { + const slugParts = data.slug.split("/"); + slugParts[0] = BLOG_FOLDER; + slug = slugParts.join("/"); + } else { + slug = pathParts + .slice(CONTENT_DEPTH) + .join("/") + .replace(/\.[^/.]+$/, ""); + slug = `${BLOG_FOLDER}/${slug.split("/").slice(1).join("/")}`; + } + data.slug = slug; + const group = "blog"; - return { - lang: languages[index].languageCode, // Set the correct language code dynamically - group: group, - slug: data.slug, - frontmatter: data, - content: content, - }; + return { + lang: languages[index].languageCode, + group: group, + slug: data.slug, + frontmatter: data, + content: content, + }; + } + } catch (error) { + console.error(`Error processing file ${filepath}:`, error); + return []; } }); }) @@ -65,21 +82,32 @@ const getData = (folder, groupDepth, langIndex = 0) => { }; try { + console.log("Starting JSON generation..."); + // create folder if it doesn't exist if (!fs.existsSync(JSON_FOLDER)) { - fs.mkdirSync(JSON_FOLDER); + console.log(`Creating JSON folder: ${JSON_FOLDER}`); + fs.mkdirSync(JSON_FOLDER, { recursive: true }); } // create json files + const posts = getData(BLOG_FOLDER, 3); + console.log(`Generated ${posts.length} posts`); + fs.writeFileSync( `${JSON_FOLDER}/posts.json`, - JSON.stringify(getData(BLOG_FOLDER, 3)), + JSON.stringify(posts, null, 2) ); // merge json files for search - const posts = require(`../${JSON_FOLDER}/posts.json`); const search = [...posts]; - fs.writeFileSync(`${JSON_FOLDER}/search.json`, JSON.stringify(search)); + fs.writeFileSync( + `${JSON_FOLDER}/search.json`, + JSON.stringify(search, null, 2) + ); + + console.log("JSON generation completed successfully"); } catch (err) { - console.error(err); + console.error("Error during JSON generation:", err); + process.exit(1); } diff --git a/src/content/blog/english/khc.md b/src/content/blog/english/khc.md index eb88632..7f27751 100644 --- a/src/content/blog/english/khc.md +++ b/src/content/blog/english/khc.md @@ -46,8 +46,12 @@ So if you're planning to join SRM-RMP, don’t just believe the brochures or the This post isn’t to bash the institution. It’s just the side of the story that doesn't make it to the official website. +<<<<<<< HEAD +--- +======= --- ## Contact Have a story or experience from your own campus you want to share anonymously? +>>>>>>> upstream/main