Skip to content

Commit

Permalink
Could redirect out of namespace url, small refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
milanmajchrak committed Dec 1, 2023
1 parent 9c882d1 commit bb3cb9c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
17 changes: 11 additions & 6 deletions src/app/static-page/static-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,20 @@ export class StaticPageComponent implements OnInit {
const element: HTMLElement = e.target;
if (element.nodeName === 'A') {
e.preventDefault();
let href = element.getAttribute('href');
href = href.replace('/', '');
// start with `#` - redirect to the fragment
const href = element.getAttribute('href')?.replace('/', '');
let redirectUrl = window.location.origin + this.appConfig.ui.nameSpace + '/static/';
// Start with `#` - redirect to the fragment
if (href.startsWith('#')) {
window.location.href = window.location.origin + this.appConfig.ui.nameSpace + '/static/' + this.htmlFileName + href;
redirectUrl += this.htmlFileName + href;
} else if (href.startsWith('.')) {
// Redirect using namespace e.g. `./test.html` -> `<UI_PATH>/namespace/static/test.html`
redirectUrl += href.replace('.', '') + '.html';
} else {
// normal redirect
window.location.href = window.location.origin + this.appConfig.ui.nameSpace + '/static/' + href + '.html';
// Redirect without using namespace e.g. `/test.html` -> `<UI_PATH>/test.html`
redirectUrl = redirectUrl.replace(this.appConfig.ui.nameSpace, '') + href;
}
// Call redirect
window.location.href = redirectUrl;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/static-files/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ <h2 id="ufal-point-faq">LINDAT/CLARIAH-CZ repository About and Policies</h2>
<li><a href="#privacy-policy">Privacy Policy</a></li>
<li><a href="#metadata-policy">Metadata Policy</a></li>
<li><a href="#preservation-policy">Preservation Policy</a></li>
<li><a href="/cite">Citing Data Policy</a></li>
<li><a href="./cite">Citing Data Policy</a></li>
</ul>
<hr />
<div>
Expand Down

0 comments on commit bb3cb9c

Please sign in to comment.