diff --git a/angular.json b/angular.json index c2a40a50..c7315ab0 100644 --- a/angular.json +++ b/angular.json @@ -47,7 +47,7 @@ }, "styles": ["styles/styles.scss"], "prerender": { - "routesFile": "routes.txt" + "routesFile": "dist/routes.txt" }, "scripts": [ "node_modules/prismjs/prism.js", diff --git a/projects/utils/src/lib/permalink.ts b/projects/utils/src/lib/permalink.ts index c819fde6..65856bac 100644 --- a/projects/utils/src/lib/permalink.ts +++ b/projects/utils/src/lib/permalink.ts @@ -25,3 +25,7 @@ export function getPermalink( return `${base}/${titleDirectoryName}`; } + +export function getAuthorPermalink(authorName: string) { + return authorName.replace(/\W/g, '-').toLowerCase(); +} diff --git a/routes.txt b/routes.txt deleted file mode 100644 index 98c11ed8..00000000 --- a/routes.txt +++ /dev/null @@ -1,29 +0,0 @@ -/2020/03/04/kubernetes-application-developer-certification-tips -/2020/07/24/building-an-ios-14-widget-to-show-account-balance -/2020/08/14/configuration-driven-ui-from-epoxy-to-compose -/2021/06/16/flexible-configuration-with-deferred-resources -/2021/09/10/hello-blockchain -/2021/12/01/the-ultimate-guide-to-slack-etiquette -/2022/06/08/deploying-an-angular-app-on-azure -/2022/07/01/ease-your-life-at-work-with-fastlane -/2022/11/16/android-mobile-testing-fragments -/2023/05/01/shift-left-approach-to-testing -/2023/05/12/ngoptimizedimage-directive-in-angular-15 -/2023/05/16/hacking-netflix-eureka -/2023/07/03/angular-standalone-components -/2023/09/29/the-better-way-with-ruby-gems -/2023/09/30/installing-hms-core-in-android-studio-emulator -/2023/10/06/code-coverage-for-unit-tests -/2023/10/25/angular-unit-testing-with-spectator -/2023/11/03/visual-testing-using-playwright -/2023/11/21/a-new-chapter-exploring-azure-resources -/2023/12/13/angular-micro-frontends -/principles/innersource -/principles/software-engineering -/category/tech-life -/category/devops -/category/backend -/category/career -/category/frontend -/category/sdlc -/404 \ No newline at end of file diff --git a/src/app/core/services/authors.service.ts b/src/app/core/services/authors.service.ts index 482b2db1..39bfa9be 100644 --- a/src/app/core/services/authors.service.ts +++ b/src/app/core/services/authors.service.ts @@ -2,6 +2,7 @@ import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Author, AuthorsList } from '../model/author.model'; import { Observable, map, shareReplay } from 'rxjs'; +import { getAuthorPermalink } from '@blog/utils'; @Injectable({ providedIn: 'root', @@ -22,7 +23,7 @@ export class AuthorsService { [curr]: { ...authors[curr], fullname: curr, - url: `people/${curr.toLowerCase().replace(/\W/g, '-')}`, + url: `/people/${getAuthorPermalink(curr)}`, }, }), {} diff --git a/tools/build-posts/index.js b/tools/build-posts/index.js index 5164b481..259c9809 100644 --- a/tools/build-posts/index.js +++ b/tools/build-posts/index.js @@ -45,9 +45,23 @@ function scanDirectory(directoryPath, filesArray, routesArray) { ); } -function main() { +async function getAuthorRoutes(source) { + if (fs.existsSync(source)) { + const authors = JSON.parse(fs.readFileSync(source, 'utf8')); + + const utils = await loadEsmModule( + '../../dist/utils/esm2022/lib/permalink.mjs' + ); + return Object.keys(authors).map(name => + `/people/${utils.getAuthorPermalink(name)}`); + } + return []; +} + +async function main() { const startDirectory = 'content/posts'; // Change this to the starting directory path const outputFilePath = 'content/posts/posts.json'; // Change this to the desired output file path + const authorsFilePath = 'content/authors/authors.json'; if (fs.existsSync(outputFilePath)) { fs.unlinkSync(outputFilePath); @@ -68,11 +82,16 @@ function main() { '/category/career', '/category/frontend', '/category/sdlc', - '/404' + '/404', + ...(await getAuthorRoutes(authorsFilePath)) ); - fs.writeFileSync('routes.txt', routesArray.join('\r\n'), 'utf8'); + fs.writeFileSync('dist/routes.txt', routesArray.join('\r\n'), 'utf8'); console.log(`Scanning completed. Output written to ${outputFilePath}`); } main(); + +function loadEsmModule(modulePath) { + return new Function('modulePath', `return import(modulePath);`)(modulePath); +}