Skip to content

Commit

Permalink
Merge pull request #2267 from ORCID/lmendoza/enable-homepage-prod
Browse files Browse the repository at this point in the history
Lmendoza/enable homepage dynamic environment assets.
  • Loading branch information
leomendoza123 authored May 28, 2024
2 parents 3582346 + ba7cd81 commit e43168c
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 9 deletions.
45 changes: 39 additions & 6 deletions src/app/core/wordpress/wordpress.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { HttpClient } from '@angular/common/http'
import { Inject, Injectable, LOCALE_ID } from '@angular/core'
import { catchError, map } from 'rxjs/operators'
import { WordpressPost } from 'src/app/types/wordpress'
import { environment } from 'src/environments/environment'

Expand All @@ -13,12 +14,44 @@ export class WordpressService {
) {}

getHomePagePost() {
return this.httpClient.get(
`${
environment.WORDPRESS_S3
}/index${this.getWordpressLocalizationCode()}.html`,
{ responseType: 'text' }
)
const primaryUrl = `${
environment.WORDPRESS_S3
}/index${this.getWordpressLocalizationCode()}.html`
const fallbackUrl = `${
environment.WORDPRESS_S3_FALLBACK
}/index${this.getWordpressLocalizationCode()}.html`

return this.httpClient
.get(primaryUrl, { responseType: 'text' })
.pipe(
map((html: string) => {
return {
html: html,
url: environment.WORDPRESS_S3,
}
})
)
.pipe(
catchError((error) => {
return this.httpClient
.get(fallbackUrl, { responseType: 'text' })
.pipe(
map((html: string) => {
return {
html: html,
url: environment.WORDPRESS_S3_FALLBACK,
}
})
)
}),
// Update resulting HTML to use the correct base URL
map((data: { html: string; url: string }) => {
const find = './assets/'
const regex = new RegExp(find, 'g')
const updatedHtml = data.html.replace(regex, data.url + '/assets/')
return updatedHtml
})
)
}
getWordpressLocalizationCode() {
if (this.locale.includes('en')) {
Expand Down
1 change: 1 addition & 0 deletions src/app/home/pages/home/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export class HomeComponent implements OnInit {
)
.subscribe((html) => {
this.wordpressView = this.sanitizer.bypassSecurityTrustHtml(html)
this.wordpressView
})
}

Expand Down
3 changes: 2 additions & 1 deletion src/environments/environment.int.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export const environment = {
CAN_DISABLE_TEST_WARNING_BANNER: true,
INSTITUTIONAL_AUTOCOMPLETE_DISPLAY_AMOUNT: 20,
VERBOSE_SNACKBAR_ERRORS_REPORTS: true,
WORDPRESS_S3: 'https://d3055hwma3riwo.cloudfront.net',
WORDPRESS_S3: 'https://d25yxmpntoa26z.cloudfront.net',
WORDPRESS_S3_FALLBACK: 'https://d1kh89kum7j2ji.cloudfront.net',
LANGUAGE_MENU_OPTIONS: {
ar: 'العربية',
cs: 'Čeština',
Expand Down
1 change: 1 addition & 0 deletions src/environments/environment.local-with-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const environment = {
INSTITUTIONAL_AUTOCOMPLETE_DISPLAY_AMOUNT: 50,
VERBOSE_SNACKBAR_ERRORS_REPORTS: true,
WORDPRESS_S3: 'https://d3055hwma3riwo.cloudfront.net',
WORDPRESS_S3_FALLBACK: 'https://d1kh89kum7j2ji.cloudfront.net',
LANGUAGE_MENU_OPTIONS: {
ar: 'العربية',
cs: 'Čeština',
Expand Down
1 change: 1 addition & 0 deletions src/environments/environment.local.tomcat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const environment = {
INSTITUTIONAL_AUTOCOMPLETE_DISPLAY_AMOUNT: 20,
VERBOSE_SNACKBAR_ERRORS_REPORTS: true,
WORDPRESS_S3: 'https://d3055hwma3riwo.cloudfront.net',
WORDPRESS_S3_FALLBACK: 'https://d1kh89kum7j2ji.cloudfront.net',
LANGUAGE_MENU_OPTIONS: {
ar: 'العربية',
cs: 'Čeština',
Expand Down
1 change: 1 addition & 0 deletions src/environments/environment.local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const environment = {
INSTITUTIONAL_AUTOCOMPLETE_DISPLAY_AMOUNT: 50,
VERBOSE_SNACKBAR_ERRORS_REPORTS: true,
WORDPRESS_S3: 'https://d3055hwma3riwo.cloudfront.net',
WORDPRESS_S3_FALLBACK: 'https://d1kh89kum7j2ji.cloudfront.net',
LANGUAGE_MENU_OPTIONS: {
ar: 'العربية',
cs: 'Čeština',
Expand Down
3 changes: 2 additions & 1 deletion src/environments/environment.production.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export const environment = {
HELP_HERO_ID: 'oYFQMrzFHA',
INSTITUTIONAL_AUTOCOMPLETE_DISPLAY_AMOUNT: 20,
VERBOSE_SNACKBAR_ERRORS_REPORTS: false,
WORDPRESS_S3: 'https://d3055hwma3riwo.cloudfront.net',
WORDPRESS_S3: 'https://d25yxmpntoa26z.cloudfront.net',
WORDPRESS_S3_FALLBACK: 'https://d1kh89kum7j2ji.cloudfront.net',
LANGUAGE_MENU_OPTIONS: {
ar: 'العربية',
cs: 'Čeština',
Expand Down
1 change: 1 addition & 0 deletions src/environments/environment.qa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const environment = {
INSTITUTIONAL_AUTOCOMPLETE_DISPLAY_AMOUNT: 20,
VERBOSE_SNACKBAR_ERRORS_REPORTS: true,
WORDPRESS_S3: 'https://d3055hwma3riwo.cloudfront.net',
WORDPRESS_S3_FALLBACK: 'https://d1kh89kum7j2ji.cloudfront.net',
LANGUAGE_MENU_OPTIONS: {
ar: 'العربية',
cs: 'Čeština',
Expand Down
3 changes: 2 additions & 1 deletion src/environments/environment.sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export const environment = {
CAN_DISABLE_TEST_WARNING_BANNER: false,
INSTITUTIONAL_AUTOCOMPLETE_DISPLAY_AMOUNT: 20,
VERBOSE_SNACKBAR_ERRORS_REPORTS: false,
WORDPRESS_S3: 'https://d3055hwma3riwo.cloudfront.net',
WORDPRESS_S3: 'https://d25yxmpntoa26z.cloudfront.net',
WORDPRESS_S3_FALLBACK: 'https://d1kh89kum7j2ji.cloudfront.net',
LANGUAGE_MENU_OPTIONS: {
ar: 'العربية',
cs: 'Čeština',
Expand Down

0 comments on commit e43168c

Please sign in to comment.