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

Lmendoza/enable homepage dynamic environment assets. #2267

Merged
merged 3 commits into from
May 28, 2024
Merged
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
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
Loading