-
Notifications
You must be signed in to change notification settings - Fork 25
Add FAIR signposting #860
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
base: feature/pbs-25-24
Are you sure you want to change the base?
Add FAIR signposting #860
Changes from all commits
bed0fd0
2f186ef
612aa83
05554bb
331da2b
c10feee
c389e75
78d78a4
8283581
3af6af1
e9fdbc1
08a5994
922f0cc
dac74ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,13 @@ import { MetaTagAuthor } from './meta-tag-author.model'; | |
|
|
||
| export type Content = string | number | null | undefined | MetaTagAuthor; | ||
|
|
||
| export interface SignpostingLink { | ||
| rel: string; | ||
| href: string; | ||
| type?: string; | ||
| title?: string; | ||
| } | ||
|
|
||
| export type DataContent = Content | Content[]; | ||
|
|
||
| export interface MetaTagsData { | ||
|
|
@@ -28,4 +35,5 @@ export interface MetaTagsData { | |
| twitterCreator?: DataContent; | ||
| contributors?: DataContent; | ||
| keywords?: DataContent; | ||
| signpostingLinks?: SignpostingLink[]; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: Similar to the above, I don't think the |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import { of } from 'rxjs'; | ||
|
|
||
| import { inject, Injectable, RESPONSE_INIT } from '@angular/core'; | ||
|
|
||
| import { SignpostingLink } from '../models/meta-tags/meta-tags-data.model'; | ||
|
|
||
| @Injectable({ | ||
| providedIn: 'root', | ||
| }) | ||
| export class SignpostingService { | ||
| private readonly responseInit = inject(RESPONSE_INIT, { optional: true }); | ||
|
|
||
| mockSignpostingLinks: SignpostingLink[] = [ | ||
| { | ||
| rel: 'describedby', | ||
| href: '/api/descriptions/project-123', | ||
| type: 'application/json', | ||
| }, | ||
| { | ||
| rel: 'cite-as', | ||
| href: 'https://doi.org/10.1234/example', | ||
| type: 'text/html', | ||
| }, | ||
| { | ||
| rel: 'item', | ||
| href: '/project/123/files/', | ||
| type: 'text/html', | ||
| title: 'Project Files', | ||
| }, | ||
| { | ||
| rel: 'collection', | ||
| href: '/user/projects/', | ||
| type: 'text/html', | ||
| title: 'User Projects', | ||
| }, | ||
| ]; | ||
|
|
||
| addSignpostingHeaders(): void { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: Should take some guid value as a parameter and build the href value based on that guid. Will likely need an additional argument to indicate if we want the URL for the metadata linkset |
||
| of(this.mockSignpostingLinks).subscribe({ | ||
| next: (links) => { | ||
| if (!this.responseInit || !this.responseInit.headers) { | ||
| return; | ||
| } | ||
|
|
||
| const headers = | ||
| this.responseInit?.headers instanceof Headers | ||
| ? this.responseInit.headers | ||
| : new Headers(this.responseInit?.headers); | ||
|
|
||
| const linkHeader = this.formatLinkHeader(links); | ||
| headers.set('Link', linkHeader); | ||
|
|
||
| this.responseInit.headers = headers; | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| formatLinkHeader(links: SignpostingLink[]): string { | ||
| return links | ||
| .map((link) => { | ||
| const parts = [`<${link.href}>`, `rel="${link.rel}"`]; | ||
| if (link.type) parts.push(`type="${link.type}"`); | ||
| if (link.title) parts.push(`title="${link.title}"`); | ||
| return parts.join('; '); | ||
| }) | ||
| .join(', '); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: Would like to avoid having to call both
signpostingService.addSignpostingHeaders()and addingsignpostingLinksto themetaTagsobject. I think my preference going forward would be to remove thesignpostingLinksfrom themetaTagsobject (since this is going to be a<link>tag) and just have the logic for adding a<link>to the head tag done within thesignpostingService.addSignpostingHeaders()function.