"use strict";
(() => {
var exports = {};
exports.id = 915;
exports.ids = [915];
exports.modules = {

/***/ 8811:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {

// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);

// EXPORTS
__webpack_require__.d(__webpack_exports__, {
  "default": () => (/* binding */ handler)
});

;// CONCATENATED MODULE: external "fs"
const external_fs_namespaceObject = require("fs");
var external_fs_default = /*#__PURE__*/__webpack_require__.n(external_fs_namespaceObject);
;// CONCATENATED MODULE: external "feed"
const external_feed_namespaceObject = require("feed");
;// CONCATENATED MODULE: ./lib/rssFetch.js
const rssFetch_getSortedPost = async ()=>{
    const res = await fetch(`${"https://api.trsondakika.com/api"}/feed`, {
        method: "GET"
    });
    const data = await res.json();
    return data;
};
const getSitemapPage = async ()=>{
    const res = await fetch(`${"https://api.trsondakika.com/api"}/sitemap_page`, {
        method: "GET"
    });
    const data = await res.json();
    return data;
};
const getSitemapCategory = async ()=>{
    const res = await fetch(`${"https://api.trsondakika.com/api"}/sitemap_category`, {
        method: "GET"
    });
    const data = await res.json();
    return data;
};
const getSitemapAuthor = async ()=>{
    const res = await fetch(`${"https://api.trsondakika.com/api"}/sitemap_author`, {
        method: "GET"
    });
    const data = await res.json();
    return data;
};
const getSitemapContent = async ()=>{
    const res = await fetch(`${"https://api.trsondakika.com/api"}/sitemap_content`, {
        method: "GET"
    });
    const data = await res.json();
    return data;
};

;// CONCATENATED MODULE: ./lib/NewUrlCheck.js
const NewUrlCheck_CheckUrlSlug = (id, category, slug)=>{
    if (category && id > 152930) {
        return `${"/"}${category}/${slug}`;
    } else {
        return `${"/"}${slug}`;
    }
};

;// CONCATENATED MODULE: ./lib/generateRSSFeed.js




async function generateRssFeed() {
    const allPosts = await getSortedPost();
    const handleKeywrods = (par)=>{
        var last = "";
        if (par) {
            const explode = par.split(",");
            explode.map((e)=>{
                last += ` #${e.replace(/\s+/g, "").trim()}`;
            });
            return last.trim();
        } else {
            return null;
        }
    };
    const site_url = "https://trsondakika.com";
    const feedOptions = {
        title: "TRSondakika - Dünyadan Son Dakika Haberler, Spor, Dünya, Politika, Sağlık, Forex, Kripto, Ekonomi, Emlak" + " - RSS Feed",
        description: "Welcome to this news posts!",
        id: site_url,
        link: site_url,
        image: `${site_url}/static/trsondakika.png`,
        favicon: `${site_url}/favicon.ico`,
        copyright: `All rights reserved ${new Date().getFullYear()},  ${"trsondakika"} `,
        generator: "Feed for Node.js",
        feedLinks: {
            rss2: `${site_url}/rss.xml`
        }
    };
    const feed = new Feed(feedOptions);
    allPosts.forEach((post)=>{
        feed.addItem({
            title: post.title,
            id: `${site_url}/${post.slug}`,
            link: `${`${"https://trsondakika.com"}${CheckUrlSlug(post.id, post.categorySlug, post.slug)}`}`,
            description: post.description,
            image: `${"https://trsondakika-front.s3.amazonaws.com"}/${post.image}`,
            content: handleKeywrods(post.keywords),
            date: new Date(post.published_at)
        });
    });
    const folderName = `./public/rss`;
    try {
        if (!fs.existsSync(folderName)) {
            // console.log("folderName:::", folderName);
            fs.mkdirSync(folderName, {
                recursive: true
            });
        }
    } catch (err) {
        console.error(err);
    }
    fs.mkdirSync("./public/rss", {
        recursive: true
    });
    fs.writeFileSync("./public/rss.xml", feed.rss2());
}
async function generateSitemapPage() {
    const items = await getSitemapPage();
    return `<?xml version="1.0" encoding="UTF-8"?>
   <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">  
     ${items.map((item)=>{
        return `
       <url>
           <loc>${`${"https://trsondakika.com"}/page/${item.slug}`}</loc>
           <lastmod>${new Date(item.updated_at).toISOString()}</lastmod>
           <priority>1.0</priority>
       </url>
     `;
    }).join("")}
   </urlset>
 `;
}
async function generateSitemapCategory() {
    const items = await getSitemapCategory();
    return `<?xml version="1.0" encoding="UTF-8"?>
   <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">  
     ${items.map((item)=>{
        return `
       <url>
           <loc>${`${"https://trsondakika.com"}/category/${item.slug}`}</loc>
           <lastmod>${item.updated_at ? new Date(item.updated_at).toISOString() : new Date().toISOString()}</lastmod>
           <priority>1.0</priority>
       </url>
     `;
    }).join("")}
   </urlset>
 `;
}
async function generateSitemapAuthor() {
    const items = await getSitemapAuthor();
    return `<?xml version="1.0" encoding="UTF-8"?>
   <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">  
     ${items.map((item)=>{
        return `
       <url>
           <loc>${`${"https://trsondakika.com"}/author/${item.username}`}</loc>
           <lastmod>${item.updated_at ? new Date(item.updated_at).toISOString() : new Date().toISOString()}</lastmod>
           <priority>1.0</priority>
       </url>
     `;
    }).join("")}
   </urlset>
 `;
}
async function generateSitemapIndex() {
    const generateAuthor = await generateSitemapAuthor();
    const generateCategory = await generateSitemapCategory();
    const generatePage = await generateSitemapPage();
    const generateContent = await getSitemapContent();
    const folderName = `./public/rss`;
    try {
        if (!external_fs_default().existsSync(folderName)) {
            external_fs_default().mkdirSync(folderName, {
                recursive: true
            });
        }
    } catch (err) {
        console.error(err);
    }
    //   fs.mkdirSync("./public/rss", { recursive: true });
    external_fs_default().writeFileSync(`${folderName}/author.xml`, generateAuthor);
    external_fs_default().writeFileSync(`${folderName}/category.xml`, generateCategory);
    external_fs_default().writeFileSync(`${folderName}/pages.xml`, generatePage);
    const createLink = (items)=>{
        return `<?xml version="1.0" encoding="UTF-8"?>
     
    <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
    ${items.map((item)=>{
            return `
      <url>
          <loc>${`${"https://trsondakika.com"}${NewUrlCheck_CheckUrlSlug(item.id, item.categorySlug, item.slug)}`}</loc>
          <lastmod>${new Date(item.published_at).toISOString()}</lastmod>          
          <priority>1.0</priority>
          <image:image>
            <image:loc>${`${"https://trsondakika-front.s3.amazonaws.com"}/${item.image}`}</image:loc>
            <image:title>${item.title}</image:title>
            <image:caption>${item.title}</image:caption>
          </image:image>
      </url>
    `;
        }).join("")}
  
  </urlset>`;
    };
    let contentSitemap = "";
    for (const [key, value] of Object.entries(generateContent)){
        contentSitemap += `
      <sitemap>
        <loc>${"https://trsondakika.com"}/rss/content-${key}.xml</loc>
        <lastmod>${new Date().toISOString()}</lastmod>
      </sitemap>
      `;
        external_fs_default().writeFileSync(`${folderName}/content-${key}.xml`, createLink(Object.values(value)));
    }
    return `<?xml version="1.0" encoding="UTF-8"?>
  <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <sitemap>
  <loc>${"https://trsondakika.com"}/rss/author.xml</loc>
  <lastmod>${new Date().toISOString()}</lastmod>
  </sitemap>
  <sitemap>
  <loc>${"https://trsondakika.com"}/rss/category.xml</loc>
  <lastmod>${new Date().toISOString()}</lastmod>
  </sitemap>
  <sitemap>
  <loc>${"https://trsondakika.com"}/rss/pages.xml</loc>
  <lastmod>${new Date().toISOString()}</lastmod>
  </sitemap>
  ${contentSitemap}
   
 </sitemapindex>`;
}

;// CONCATENATED MODULE: ./pages/api/regenerate-sitemap.js

function handler(req, res) {
    if (req.method !== "GET" && req.method !== "POST") {
        return res.status(405).json({
            error: "Method not allowed"
        });
    }
    const secret = req.headers["x-cron-secret"] || req.query.secret;
    if (true) {
        return res.status(401).json({
            error: "Unauthorized"
        });
    }
    return generateSitemapIndex().then(()=>{
        res.status(200).json({
            success: true,
            regeneratedAt: new Date().toISOString()
        });
    }).catch((err)=>{
        console.error("Sitemap regeneration failed:", err);
        res.status(500).json({
            error: "Sitemap regeneration failed"
        });
    });
}


/***/ })

};
;

// load runtime
var __webpack_require__ = require("../../webpack-api-runtime.js");
__webpack_require__.C(exports);
var __webpack_exec__ = (moduleId) => (__webpack_require__(__webpack_require__.s = moduleId))
var __webpack_exports__ = (__webpack_exec__(8811));
module.exports = __webpack_exports__;

})();