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

WORDPRESS_HOME_PAGE #2171

Merged
merged 2 commits into from
Feb 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
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
"storybook": "ng run ng-orcid:storybook ",
"build:storybook": "ng run ng-orcid:build-storybook",
"lighthouse": "ts-node -P scripts/tsconfig.json scripts/lighthouse/main.ts",
"build:browserslist": "ts-node -P scripts/tsconfig.json scripts/browserlist.prebuild.ts"
"build:browserslist": "ts-node -P scripts/tsconfig.json scripts/browserlist.prebuild.ts",
"build:fetchCombineWordpressCss": "ts-node -P scripts/tsconfig.json scripts/fetch-combine-wordpress-css.prebuild"

},
"private": true,
"dependencies": {
Expand Down
52 changes: 52 additions & 0 deletions scripts/fetch-combine-wordpress-css.prebuild.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Import fetch if it's not globally available (uncomment if needed)
// const fetch = require('node-fetch');
const fs = require('fs')

// URLs of the CSS files
const cssUrls = [
'https://info.orcid.org/wp-content/themes/orcid-outreach-pro/style.css',
'https://info.orcid.org/wp-includes/css/dist/block-library/style.css',
'https://info.orcid.org/wp-content/plugins/genesis-blocks/dist/style-blocks.build.css',
]

// Function to fetch and combine CSS content
async function fetchAndCombineCSS(urls) {
let combinedCSS = '::ng-deep .wordpress-styles {\n' // Starting the wrapper class

for (const url of urls) {
try {
const response = await fetch(url)
let data = await response.text()
data = data.replace(/@charset "UTF-8";\s*/g, '') // REMOVE CHARSET
data = data.replace(
/\} \*\/[\s\S]*?\/\* ROB 10\/07\/22 /g,
'/* ROB 10/07/22 '
) // REMOVE A ERROR WITH THE ORIGINAL CSS
data = data.replace(/.*\.png.*\n/g, '') // REMOBE IMAGES
data = data.replace(/:root\s*\{([\s\S]*?)\}/g, '$1') // UNWRAPS THE :root variables

combinedCSS += ` /* Content from ${url} */\n`
combinedCSS += data + '\n' // Add the CSS content
} catch (error) {
console.error(`Failed to fetch CSS from ${url}: ${error}`)
}
}

combinedCSS += '}' // Closing the wrapper class

// Writing the combined CSS to a SCSS file
fs.writeFile(
'src/app/home/pages/home/wordpress-styles.scss',
combinedCSS,
(err) => {
if (err) {
console.error('Failed to write SCSS file:', err)
} else {
console.log('Successfully wrote combined.scss')
}
}
)
}

// Run the function
fetchAndCombineCSS(cssUrls)
3 changes: 1 addition & 2 deletions src/app/cdk/platform-info/browserlist.regexp.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
// tslint:disable-next-line: max-line-length
export const BROWSERLIST_REGEXP =
/((CPU[ +]OS|iPhone[ +]OS|CPU[ +]iPhone|CPU IPhone OS)[ +]+(13[_.]4|13[_.]([5-9]|\d{2,})|13[_.]7|13[_.]([8-9]|\d{2,})|(1[4-9]|[2-9]\d|\d{3,})[_.]\d+|14[_.]0|14[_.]([1-9]|\d{2,})|14[_.]4|14[_.]([5-9]|\d{2,})|14[_.]8|14[_.](9|\d{2,})|(1[5-9]|[2-9]\d|\d{3,})[_.]\d+|15[_.]0|15[_.]([1-9]|\d{2,})|(1[6-9]|[2-9]\d|\d{3,})[_.]\d+|16[_.]0|16[_.]([1-9]|\d{2,})|(1[7-9]|[2-9]\d|\d{3,})[_.]\d+|17[_.]0|17[_.]([1-9]|\d{2,})|(1[8-9]|[2-9]\d|\d{3,})[_.]\d+)(?:[_.]\d+)?)|((?:Chrome).*OPR\/(74|(7[5-9]|[8-9]\d|\d{3,}))\.\d+\.\d+)|(Edge\/(80|(8[1-9]|9\d|\d{3,})|83|(8[4-9]|9\d|\d{3,}))(?:\.\d+)?)|((Chromium|Chrome)\/(80|(8[1-9]|9\d|\d{3,})|83|(8[4-9]|9\d|\d{3,}))\.\d+(?:\.\d+)?)|(Version\/(13\.1|13\.([2-9]|\d{2,})|(1[4-9]|[2-9]\d|\d{3,})\.\d+|14\.0|14\.([1-9]|\d{2,})|(1[5-9]|[2-9]\d|\d{3,})\.\d+|15\.0|15\.([1-9]|\d{2,})|(1[6-9]|[2-9]\d|\d{3,})\.\d+|16\.0|16\.([1-9]|\d{2,})|(1[7-9]|[2-9]\d|\d{3,})\.\d+|17\.0|17\.([1-9]|\d{2,})|(1[8-9]|[2-9]\d|\d{3,})\.\d+)(?:\.\d+)? Safari\/)|(Firefox\/(78|(79|[8-9]\d|\d{3,}))\.\d+\.\d+)|(Firefox\/(78|(79|[8-9]\d|\d{3,}))\.\d+(pre|[ab]\d+[a-z]*)?)/
export const BROWSERLIST_REGEXP = /((CPU[ +]OS|iPhone[ +]OS|CPU[ +]iPhone|CPU IPhone OS)[ +]+(13[_.]4|13[_.]([5-9]|\d{2,})|13[_.]7|13[_.]([8-9]|\d{2,})|(1[4-9]|[2-9]\d|\d{3,})[_.]\d+|14[_.]0|14[_.]([1-9]|\d{2,})|14[_.]4|14[_.]([5-9]|\d{2,})|14[_.]8|14[_.](9|\d{2,})|(1[5-9]|[2-9]\d|\d{3,})[_.]\d+|15[_.]0|15[_.]([1-9]|\d{2,})|(1[6-9]|[2-9]\d|\d{3,})[_.]\d+|16[_.]0|16[_.]([1-9]|\d{2,})|(1[7-9]|[2-9]\d|\d{3,})[_.]\d+|17[_.]0|17[_.]([1-9]|\d{2,})|(1[8-9]|[2-9]\d|\d{3,})[_.]\d+)(?:[_.]\d+)?)|((?:Chrome).*OPR\/(74|(7[5-9]|[8-9]\d|\d{3,}))\.\d+\.\d+)|(Edge\/(80|(8[1-9]|9\d|\d{3,})|83|(8[4-9]|9\d|\d{3,}))(?:\.\d+)?)|((Chromium|Chrome)\/(80|(8[1-9]|9\d|\d{3,})|83|(8[4-9]|9\d|\d{3,}))\.\d+(?:\.\d+)?)|(Version\/(13\.1|13\.([2-9]|\d{2,})|(1[4-9]|[2-9]\d|\d{3,})\.\d+|14\.0|14\.([1-9]|\d{2,})|(1[5-9]|[2-9]\d|\d{3,})\.\d+|15\.0|15\.([1-9]|\d{2,})|(1[6-9]|[2-9]\d|\d{3,})\.\d+|16\.0|16\.([1-9]|\d{2,})|(1[7-9]|[2-9]\d|\d{3,})\.\d+|17\.0|17\.([1-9]|\d{2,})|(1[8-9]|[2-9]\d|\d{3,})\.\d+)(?:\.\d+)? Safari\/)|(Firefox\/(78|(79|[8-9]\d|\d{3,}))\.\d+\.\d+)|(Firefox\/(78|(79|[8-9]\d|\d{3,}))\.\d+(pre|[ab]\d+[a-z]*)?)/
23 changes: 23 additions & 0 deletions src/app/core/wordpress/wordpress.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { TestBed } from '@angular/core/testing'

import { WordpressService } from './wordpress.service'
import { HttpClientTestingModule } from '@angular/common/http/testing'
import { RouterTestingModule } from '@angular/router/testing'
import { PlatformInfoService } from 'src/app/cdk/platform-info'
import { WINDOW_PROVIDERS } from 'src/app/cdk/window'

describe('WordpressService', () => {
let service: WordpressService

beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule, RouterTestingModule],
providers: [WINDOW_PROVIDERS, PlatformInfoService],
})
service = TestBed.inject(WordpressService)
})

it('should be created', () => {
expect(service).toBeTruthy()
})
})
29 changes: 29 additions & 0 deletions src/app/core/wordpress/wordpress.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { HttpClient } from '@angular/common/http'
import { Inject, Injectable, LOCALE_ID } from '@angular/core'
import { WordpressPost } from 'src/app/types/wordpress'
import { environment } from 'src/environments/environment'

@Injectable({
providedIn: 'root',
})
export class WordpressService {
constructor(
private httpClient: HttpClient,
@Inject(LOCALE_ID) public locale: string
) {}

getHomePagePost() {
return this.httpClient.get<WordpressPost>(
environment.WORDPRESS_API +
this.getWordpressLocalizationCode() +
'/wp-json/wp/v2/posts/' +
(localStorage.getItem('homeId') || environment.WORDPRESS_API_HOME_ID)
)
}
getWordpressLocalizationCode() {
if (this.locale.includes('en')) {
return ''
}
return this.locale
}
}
Loading
Loading