Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add authors to routes.txt file #88

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
},
"styles": ["styles/styles.scss"],
"prerender": {
"routesFile": "routes.txt"
"routesFile": "dist/routes.txt"
},
"scripts": [
"node_modules/prismjs/prism.js",
Expand Down
4 changes: 4 additions & 0 deletions projects/utils/src/lib/permalink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ export function getPermalink(

return `${base}/${titleDirectoryName}`;
}

export function getAuthorPermalink(authorName: string) {
return authorName.replace(/\W/g, '-').toLowerCase();
}
29 changes: 0 additions & 29 deletions routes.txt

This file was deleted.

3 changes: 2 additions & 1 deletion src/app/core/services/authors.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -22,7 +23,7 @@ export class AuthorsService {
[curr]: {
...authors[curr],
fullname: curr,
url: `people/${curr.toLowerCase().replace(/\W/g, '-')}`,
url: `/people/${getAuthorPermalink(curr)}`,
},
}),
{}
Expand Down
25 changes: 22 additions & 3 deletions tools/build-posts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Loading