"use strict";
exports.id = 386;
exports.ids = [386];
exports.modules = {

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

/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */   "Pt": () => (/* binding */ generateSitemapIndex),
/* harmony export */   "TX": () => (/* binding */ generateSitemapAuthor),
/* harmony export */   "a2": () => (/* binding */ generateSitemapCategory),
/* harmony export */   "eB": () => (/* binding */ generateRssFeed),
/* harmony export */   "wb": () => (/* binding */ generateSitemapPage)
/* harmony export */ });
/* harmony import */ var fs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(7147);
/* harmony import */ var fs__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(fs__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var feed__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(4582);
/* harmony import */ var feed__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(feed__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var _rssFetch__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(9956);
/* harmony import */ var _lib_NewUrlCheck__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(8953);




async function generateRssFeed() {
    const allPosts = await (0,_rssFetch__WEBPACK_IMPORTED_MODULE_2__/* .getSortedPost */ .bF)();
    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__WEBPACK_IMPORTED_MODULE_1__.Feed(feedOptions);
    allPosts.forEach((post)=>{
        feed.addItem({
            title: post.title,
            id: `${site_url}/${post.slug}`,
            link: `${`${"https://trsondakika.com"}${(0,_lib_NewUrlCheck__WEBPACK_IMPORTED_MODULE_3__/* .CheckUrlSlug */ .v)(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__WEBPACK_IMPORTED_MODULE_0___default().existsSync(folderName)) {
            // console.log("folderName:::", folderName);
            fs__WEBPACK_IMPORTED_MODULE_0___default().mkdirSync(folderName, {
                recursive: true
            });
        }
    } catch (err) {
        console.error(err);
    }
    fs__WEBPACK_IMPORTED_MODULE_0___default().mkdirSync("./public/rss", {
        recursive: true
    });
    fs__WEBPACK_IMPORTED_MODULE_0___default().writeFileSync("./public/rss.xml", feed.rss2());
}
async function generateSitemapPage() {
    const items = await (0,_rssFetch__WEBPACK_IMPORTED_MODULE_2__/* .getSitemapPage */ .on)();
    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 (0,_rssFetch__WEBPACK_IMPORTED_MODULE_2__/* .getSitemapCategory */ .UW)();
    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 (0,_rssFetch__WEBPACK_IMPORTED_MODULE_2__/* .getSitemapAuthor */ .M3)();
    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 (0,_rssFetch__WEBPACK_IMPORTED_MODULE_2__/* .getSitemapContent */ .yM)();
    const folderName = `./public/rss`;
    try {
        if (!fs__WEBPACK_IMPORTED_MODULE_0___default().existsSync(folderName)) {
            fs__WEBPACK_IMPORTED_MODULE_0___default().mkdirSync(folderName, {
                recursive: true
            });
        }
    } catch (err) {
        console.error(err);
    }
    //   fs.mkdirSync("./public/rss", { recursive: true });
    fs__WEBPACK_IMPORTED_MODULE_0___default().writeFileSync(`${folderName}/author.xml`, generateAuthor);
    fs__WEBPACK_IMPORTED_MODULE_0___default().writeFileSync(`${folderName}/category.xml`, generateCategory);
    fs__WEBPACK_IMPORTED_MODULE_0___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"}${(0,_lib_NewUrlCheck__WEBPACK_IMPORTED_MODULE_3__/* .CheckUrlSlug */ .v)(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>
      `;
        fs__WEBPACK_IMPORTED_MODULE_0___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>`;
}


/***/ })

};
;