-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #422 from sharemindteam/feat/sitemap_421
[Feat] sitemap 작성 스크립트 구현 및 자동화
- Loading branch information
Showing
11 changed files
with
159 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import fs from 'fs'; | ||
import { SitemapStream } from 'sitemap'; | ||
import axios from 'axios'; | ||
import { configDotenv } from 'dotenv'; | ||
|
||
// load env file | ||
configDotenv(); | ||
|
||
const generateSitemap = async () => { | ||
const hostname = 'https://sharemindapp.com'; | ||
|
||
// 정적 경로 | ||
const staticRoutes = [ | ||
{ url: '/', changefreq: 'monthly', priority: 0.3 }, | ||
{ url: '/share', changefreq: 'hourly', priority: 1.0 }, | ||
{ url: '/open-consult', changefreq: 'always', priority: 1.0 }, | ||
{ url: '/open-consult/likes', changefreq: 'always', priority: 0.8 }, | ||
{ url: '/open-consult/recents', changefreq: 'always', priority: 0.8 }, | ||
{ url: '/categorySearch', changefreq: 'daily', priority: 0.7 }, | ||
{ url: '/service', changefreq: 'never', priority: 0.8 }, | ||
{ url: '/service-unavailable', changefreq: 'monthly', priority: 0.5 }, | ||
]; | ||
|
||
// 동적 경로 | ||
const dynamicRoutes = []; | ||
|
||
try { | ||
const counselorAllResponse = await axios.patch( | ||
process.env.REACT_APP_API_URL + 'counselors/all?sortType=POPULARITY', | ||
{ | ||
index: 0, | ||
}, | ||
{ | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}, | ||
); | ||
|
||
const profileDynamicRoutes = counselorAllResponse.data.map((counselor) => ({ | ||
url: `/profile/${counselor.counselorId}`, | ||
changefreq: 'daily', | ||
priority: 0.7, | ||
})); | ||
|
||
dynamicRoutes.push(...profileDynamicRoutes); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
|
||
try { | ||
const likesResponse = await axios.get( | ||
process.env.REACT_APP_API_URL + | ||
'posts/customers/public/likes?postId=0&finishedAt=' + | ||
new Date().toISOString().slice(0, 19), | ||
{ | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}, | ||
); | ||
|
||
const likesDynamicRoutes = likesResponse.data.map((post) => ({ | ||
url: `/open-consult/${post.postId}`, | ||
changefreq: 'daily', | ||
priority: 0.7, | ||
})); | ||
|
||
dynamicRoutes.push(...likesDynamicRoutes); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
|
||
// Sitemap 생성 | ||
const sitemap = new SitemapStream({ hostname }); | ||
const writeStream = fs.createWriteStream('./public/sitemap.xml'); | ||
|
||
sitemap.pipe(writeStream); | ||
|
||
// 정적 경로 추가 | ||
staticRoutes.forEach((route) => sitemap.write(route)); | ||
|
||
// 동적 경로 추가 | ||
dynamicRoutes.forEach((route) => sitemap.write(route)); | ||
|
||
// 종료 | ||
sitemap.end(); | ||
|
||
// 파일 쓰기 완료 이벤트 | ||
writeStream.on('finish', () => { | ||
console.log('Sitemap successfully written to file!'); | ||
}); | ||
|
||
writeStream.on('error', (err) => { | ||
console.error('Error writing sitemap:', err); | ||
}); | ||
}; | ||
|
||
generateSitemap(); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# https://www.robotstxt.org/robotstxt.html | ||
User-agent: * | ||
Disallow: | ||
|
||
Sitemap: https://sharemindapp.com/sitemap.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/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"><url><loc>https://sharemindapp.com/</loc><changefreq>monthly</changefreq><priority>0.3</priority></url><url><loc>https://sharemindapp.com/share</loc><changefreq>hourly</changefreq><priority>1.0</priority></url><url><loc>https://sharemindapp.com/open-consult</loc><changefreq>always</changefreq><priority>1.0</priority></url><url><loc>https://sharemindapp.com/open-consult/likes</loc><changefreq>always</changefreq><priority>0.8</priority></url><url><loc>https://sharemindapp.com/open-consult/recents</loc><changefreq>always</changefreq><priority>0.8</priority></url><url><loc>https://sharemindapp.com/categorySearch</loc><changefreq>daily</changefreq><priority>0.7</priority></url><url><loc>https://sharemindapp.com/service</loc><changefreq>never</changefreq><priority>0.8</priority></url><url><loc>https://sharemindapp.com/service-unavailable</loc><changefreq>monthly</changefreq><priority>0.5</priority></url><url><loc>https://sharemindapp.com/profile/34</loc><changefreq>daily</changefreq><priority>0.7</priority></url><url><loc>https://sharemindapp.com/profile/38</loc><changefreq>daily</changefreq><priority>0.7</priority></url><url><loc>https://sharemindapp.com/profile/43</loc><changefreq>daily</changefreq><priority>0.7</priority></url><url><loc>https://sharemindapp.com/profile/73</loc><changefreq>daily</changefreq><priority>0.7</priority></url><url><loc>https://sharemindapp.com/open-consult/2</loc><changefreq>daily</changefreq><priority>0.7</priority></url><url><loc>https://sharemindapp.com/open-consult/1</loc><changefreq>daily</changefreq><priority>0.7</priority></url></urlset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters