-
Notifications
You must be signed in to change notification settings - Fork 2
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 #241 from valerymelou/feature/prerender-articles
feat: pre-render articles
- Loading branch information
Showing
40 changed files
with
917 additions
and
304 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
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 |
---|---|---|
|
@@ -43,3 +43,4 @@ Thumbs.db | |
.angular | ||
.env | ||
.firebaserc | ||
routes.txt |
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,3 @@ | ||
{ | ||
"eslint.validate": ["json"] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Allow URLs (see https://www.robotstxt.org/robotstxt.html) | ||
User-agent: * | ||
Disallow: |
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 @@ | ||
export * from './lib/article'; | ||
export * from './lib/article.resolver'; | ||
export * from './lib/articles.resolver'; | ||
export * from './lib/article.service'; | ||
export * from './lib/results'; |
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,37 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { | ||
ActivatedRouteSnapshot, | ||
ResolveFn, | ||
RouterStateSnapshot, | ||
} from '@angular/router'; | ||
|
||
import { of } from 'rxjs'; | ||
|
||
import { Article } from './article'; | ||
import { articleResolver } from './article.resolver'; | ||
import { ArticleService } from './article.service'; | ||
|
||
describe('articleResolver', () => { | ||
const executeResolver: ResolveFn<Article> = (...resolverParameters) => | ||
TestBed.runInInjectionContext(() => articleResolver(...resolverParameters)); | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [ | ||
{ | ||
provide: ArticleService, | ||
useValue: { getOne: () => of(new Article()) }, | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
it('should get the article', () => { | ||
const route: unknown = { params: { slug: '2024-07-20-test-article' } }; | ||
const articleService = TestBed.inject(ArticleService); | ||
const getOneSpy = jest.spyOn(articleService, 'getOne'); | ||
|
||
executeResolver(route as ActivatedRouteSnapshot, {} as RouterStateSnapshot); | ||
expect(getOneSpy).toHaveBeenCalledWith('test-article'); | ||
}); | ||
}); |
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,12 @@ | ||
import { inject } from '@angular/core'; | ||
import { ResolveFn } from '@angular/router'; | ||
|
||
import { Article } from './article'; | ||
import { ArticleService } from './article.service'; | ||
|
||
export const articleResolver: ResolveFn<Article> = (route) => { | ||
const articleService = inject(ArticleService); | ||
const slug = route.params['slug'].split('-').slice(3).join('-'); | ||
|
||
return articleService.getOne(slug); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { | ||
ActivatedRouteSnapshot, | ||
ResolveFn, | ||
RouterStateSnapshot, | ||
} from '@angular/router'; | ||
|
||
import { articlesResolver } from './articles.resolver'; | ||
import { Results } from './results'; | ||
import { Article } from './article'; | ||
import { ArticleService } from './article.service'; | ||
import { of } from 'rxjs'; | ||
|
||
describe('articlesResolver', () => { | ||
const executeResolver: ResolveFn<Results<Article>> = ( | ||
...resolverParameters | ||
) => | ||
TestBed.runInInjectionContext(() => | ||
articlesResolver(...resolverParameters), | ||
); | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [ | ||
{ | ||
provide: ArticleService, | ||
useValue: { | ||
get: () => of({ items: [new Article(), new Article()] }), | ||
}, | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
it('should get the articles', () => { | ||
const articleService = TestBed.inject(ArticleService); | ||
const getSpy = jest.spyOn(articleService, 'get'); | ||
|
||
executeResolver({} as ActivatedRouteSnapshot, {} as RouterStateSnapshot); | ||
expect(getSpy).toHaveBeenCalled(); | ||
}); | ||
}); |
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,12 @@ | ||
import { inject } from '@angular/core'; | ||
import { ResolveFn } from '@angular/router'; | ||
|
||
import { Article } from './article'; | ||
import { Results } from './results'; | ||
import { ArticleService } from './article.service'; | ||
|
||
export const articlesResolver: ResolveFn<Results<Article>> = () => { | ||
const articleService = inject(ArticleService); | ||
|
||
return articleService.get({}); | ||
}; |
Oops, something went wrong.