forked from DSpace/dspace-angular
-
Notifications
You must be signed in to change notification settings - Fork 2
Add deployed-version info: VERSION_D at /static/VERSION_D (#813) #1478
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7f566f9
Add deployed-version info feature: serve VERSION_D at /static/VERSION…
7bcde23
Add src/static-files placeholder so VERSION_D is generated & served (…
8012b3a
Scope static-files asset to VERSION_D.html; fix eslint (import sort, …
4cc70b8
Trim comments to match dtq-dev; drop issue refs and redundant notes
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,38 @@ | ||
| import subprocess | ||
| import sys | ||
| from datetime import datetime, timezone | ||
|
|
||
| # when next editing this script, please introduce argparse. | ||
| # do not forget, it is called in BE by .github\workflows\reusable-docker-build.yml | ||
| # argparse must be introduced there. | ||
| # that action also calls BE version of this script, which is different (BE: scripts/sourceversion.py). | ||
| # It must also cooperate with argparse | ||
|
|
||
| # the idea is, that this will be different on each branch, but could be possibly passed by argv/argparse | ||
| RELEASE_TAG_BASE='none' | ||
|
|
||
| def get_time_in_timezone(zone: str = "Europe/Bratislava"): | ||
| try: | ||
| from zoneinfo import ZoneInfo | ||
| my_tz = ZoneInfo(zone) | ||
| except Exception as e: | ||
| my_tz = timezone.utc | ||
| return datetime.now(my_tz) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| ts = get_time_in_timezone() | ||
| # we have html tags, since this script ends up creating VERSION_D.html | ||
| print(f"<h4>This info was generated on: <br> <strong> {ts.strftime('%Y-%m-%d %H:%M:%S %Z%z')} </strong> </h4>") | ||
|
|
||
| cmd = 'git log -1 --pretty=format:"<h4>Git hash: <br><strong> %H </strong> <br> Date of commit: <br> <strong> %ai </strong></h4>"' | ||
| subprocess.check_call(cmd, shell=True) | ||
|
|
||
| # when adding argparse, this should be a bit more obvious | ||
| link = sys.argv[1] + sys.argv[2] | ||
| print('<br> <h4>Build run: </h4> <a href="' + link + '"> ' + link + '</a> ') | ||
|
Kasinhou marked this conversation as resolved.
|
||
|
|
||
| link = "https://github.com/dataquest-dev/dspace-angular/releases/tag/" \ | ||
| + RELEASE_TAG_BASE + "-" + datetime.now().strftime('%Y.%m.') + sys.argv[2] | ||
|
|
||
| print('<br> <br> <h4>Release link: </h4><a href="' + link + '"> ' + link + '</a> (if it does not work, then this is not an official release instance) ') | ||
This file contains hidden or 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 hidden or 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,83 @@ | ||
| import { isPlatformBrowser } from '@angular/common'; | ||
| import { HttpClient } from '@angular/common/http'; | ||
| import { | ||
| Inject, | ||
| Injectable, | ||
| PLATFORM_ID, | ||
| } from '@angular/core'; | ||
| import { | ||
| firstValueFrom, | ||
| of, | ||
| } from 'rxjs'; | ||
| import { | ||
| catchError, | ||
| map, | ||
| } from 'rxjs/operators'; | ||
|
|
||
| import { LocaleService } from '../core/locale/locale.service'; | ||
| import { | ||
| HTML_SUFFIX, | ||
| STATIC_FILES_PROJECT_PATH, | ||
| } from '../static-page/static-page-routing-paths'; | ||
|
|
||
| interface HtmlContentResult { | ||
| found: boolean; | ||
| body: string; | ||
| } | ||
|
|
||
| /** | ||
| * Service for loading static `.html` files stored in the `/static-files` folder. | ||
| */ | ||
| @Injectable({ | ||
| providedIn: 'root', | ||
| }) | ||
| export class HtmlContentService { | ||
| constructor( | ||
| private http: HttpClient, | ||
| private localeService: LocaleService, | ||
| @Inject(PLATFORM_ID) private platformId: object, | ||
| ) {} | ||
|
|
||
| private withSuffix(name: string): string { | ||
| return name.endsWith(HTML_SUFFIX) ? name : name + HTML_SUFFIX; | ||
| } | ||
|
|
||
| private fetch(url: string) { | ||
| return this.http.get(url, { responseType: 'text' }).pipe( | ||
| map((body): HtmlContentResult => ({ found: true, body })), | ||
| catchError(() => of<HtmlContentResult>({ found: false, body: '' })), | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Load the html content for a file name, trying the current locale package first | ||
| * (`static-files/<lang>/<file>.html`) and falling back to the default package | ||
| * (`static-files/<file>.html`). Returns `undefined` when nothing was found. | ||
| * | ||
| * The files are fetched client-side only; during SSR this resolves to `undefined` | ||
| * and the content is loaded after hydration. | ||
| */ | ||
| async getHtmlContentByPathAndLocale(fileName: string): Promise<string | undefined> { | ||
| if (!isPlatformBrowser(this.platformId)) { | ||
| return undefined; | ||
| } | ||
|
|
||
| let language = await firstValueFrom(this.localeService.getCurrentLanguageCode()); | ||
| // Default language `en` lives in the non-translated (root) package. | ||
| language = language === 'en' ? '' : language; | ||
|
|
||
| if (language) { | ||
| const localized = await firstValueFrom( | ||
| this.fetch(this.withSuffix(`${STATIC_FILES_PROJECT_PATH}/${language}/${fileName}`)), | ||
| ); | ||
| if (localized.found) { | ||
| return localized.body; | ||
| } | ||
| } | ||
|
|
||
| const fallback = await firstValueFrom( | ||
| this.fetch(this.withSuffix(`${STATIC_FILES_PROJECT_PATH}/${fileName}`)), | ||
| ); | ||
| return fallback.found ? fallback.body : undefined; | ||
| } | ||
| } |
This file contains hidden or 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,22 @@ | ||
| import { | ||
| Pipe, | ||
| PipeTransform, | ||
| } from '@angular/core'; | ||
| import { | ||
| DomSanitizer, | ||
| SafeHtml, | ||
| } from '@angular/platform-browser'; | ||
|
|
||
| /** | ||
| * Pipe to keep html tags (e.g. `id`) when rendering a string via `[innerHTML]`. | ||
| */ | ||
| @Pipe({ | ||
| name: 'dsSafeHtml', | ||
| }) | ||
| export class ClarinSafeHtmlPipe implements PipeTransform { | ||
| constructor(private sanitized: DomSanitizer) {} | ||
|
|
||
| transform(htmlString: string): SafeHtml { | ||
| return this.sanitized.bypassSecurityTrustHtml(htmlString ?? ''); | ||
| } | ||
| } | ||
|
Kasinhou marked this conversation as resolved.
|
||
This file contains hidden or 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,10 @@ | ||
| import { Route } from '@angular/router'; | ||
|
|
||
| import { StaticPageComponent } from './static-page.component'; | ||
|
|
||
| export const ROUTES: Route[] = [ | ||
| { | ||
| path: ':id', | ||
| component: StaticPageComponent, | ||
| }, | ||
| ]; |
This file contains hidden or 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,8 @@ | ||
| /** | ||
| * Constants for the `/static` route. | ||
| */ | ||
| export const STATIC_PAGE_PATH = 'static'; | ||
|
|
||
| export const STATIC_FILES_PROJECT_PATH = 'static-files'; | ||
|
|
||
| export const HTML_SUFFIX = '.html'; |
This file contains hidden or 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,28 @@ | ||
| @if (contentState === 'loading') { | ||
| <div class="container text-center my-5"> | ||
| <div class="spinner-border" role="status"> | ||
| <span class="visually-hidden">{{ 'loading.default' | translate }}</span> | ||
| </div> | ||
| </div> | ||
| } | ||
|
|
||
| <!-- Show static page content when found --> | ||
| @if (contentState === 'found') { | ||
| <div class="container"> | ||
| <div [innerHTML]="htmlContent | dsSafeHtml"></div> | ||
| </div> | ||
| } | ||
|
|
||
| <!-- Show 404 error when content not found --> | ||
| @if (contentState === 'not-found') { | ||
| <div class="container page-not-found"> | ||
| <h1>404</h1> | ||
| <h2><small>{{ 'static-page.404.page-not-found' | translate }}</small></h2> | ||
| <br/> | ||
| <p>{{ 'static-page.404.help' | translate }}</p> | ||
| <br/> | ||
| <p class="text-center"> | ||
| <a routerLink="/home" class="btn btn-primary">{{ 'static-page.404.link.home-page' | translate }}</a> | ||
| </p> | ||
| </div> | ||
| } |
This file contains hidden or 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,5 @@ | ||
| .page-not-found { | ||
| text-align: center; | ||
| margin-top: 3rem; | ||
| margin-bottom: 3rem; | ||
| } |
This file contains hidden or 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,83 @@ | ||
| import { | ||
| ChangeDetectorRef, | ||
| Component, | ||
| OnInit, | ||
| } from '@angular/core'; | ||
| import { | ||
| ActivatedRoute, | ||
| RouterLink, | ||
| } from '@angular/router'; | ||
| import { TranslateModule } from '@ngx-translate/core'; | ||
|
|
||
| import { ServerResponseService } from '../core/services/server-response.service'; | ||
| import { HtmlContentService } from '../shared/html-content.service'; | ||
| import { ClarinSafeHtmlPipe } from '../shared/utils/clarin-safehtml.pipe'; | ||
|
|
||
| /** | ||
| * Component which load and show static files from the `static-files` folder. | ||
| * E.g., `<UI_URL>/static/some_file` loads the content from `static-files/some_file.html`. | ||
| */ | ||
|
Kasinhou marked this conversation as resolved.
|
||
| @Component({ | ||
| selector: 'ds-static-page', | ||
| templateUrl: './static-page.component.html', | ||
| styleUrls: ['./static-page.component.scss'], | ||
| imports: [ | ||
| ClarinSafeHtmlPipe, | ||
| RouterLink, | ||
| TranslateModule, | ||
| ], | ||
| }) | ||
| export class StaticPageComponent implements OnInit { | ||
| htmlContent = ''; | ||
| contentState: 'loading' | 'found' | 'not-found' = 'loading'; | ||
|
|
||
| constructor( | ||
| private htmlContentService: HtmlContentService, | ||
| private route: ActivatedRoute, | ||
| private responseService: ServerResponseService, | ||
| private changeDetector: ChangeDetectorRef, | ||
| ) {} | ||
|
|
||
| async ngOnInit(): Promise<void> { | ||
| this.contentState = 'loading'; | ||
| this.htmlContent = ''; | ||
|
|
||
| const fileName = this.getHtmlFileName(); | ||
| if (!fileName) { | ||
| this.markNotFound(); | ||
| return; | ||
| } | ||
|
|
||
| try { | ||
| const content = await this.htmlContentService.getHtmlContentByPathAndLocale(fileName); | ||
| if (content !== undefined) { | ||
| this.htmlContent = content; | ||
| this.contentState = 'found'; | ||
| this.changeDetector.detectChanges(); | ||
| return; | ||
| } | ||
| } catch { | ||
| // fall through to not-found handling below | ||
| } | ||
|
|
||
| this.markNotFound(); | ||
| } | ||
|
Kasinhou marked this conversation as resolved.
|
||
|
|
||
| private markNotFound(): void { | ||
| this.responseService.setNotFound(); | ||
| this.contentState = 'not-found'; | ||
| this.changeDetector.detectChanges(); | ||
| } | ||
|
|
||
| /** | ||
| * Read the file name from the URL - `static/FILE_NAME`. | ||
| */ | ||
| private getHtmlFileName(): string | null { | ||
| const id = this.route.snapshot.paramMap.get('id'); | ||
| if (!id) { | ||
| return null; | ||
| } | ||
| // Drop any trailing fragment, e.g. `VERSION_D#section`. | ||
| return id.split('#')[0]; | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 @@ | ||
| <!-- Regenerated at build time by scripts/sourceversion.py and served at /static/VERSION_D. --> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.