Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { FixSpecialCharPipe } from '@osf/shared/pipes/fix-special-char.pipe';
import { CustomDialogService } from '@osf/shared/services/custom-dialog.service';
import { DataciteService } from '@osf/shared/services/datacite/datacite.service';
import { MetaTagsService } from '@osf/shared/services/meta-tags.service';
import { SignpostingService } from '@osf/shared/services/signposting.service';
import { ToastService } from '@osf/shared/services/toast.service';
import { ContributorsSelectors } from '@osf/shared/stores/contributors';

Expand Down Expand Up @@ -104,6 +105,7 @@ export class PreprintDetailsComponent implements OnInit, OnDestroy {
private readonly prerenderReady = inject(PrerenderReadyService);
private readonly platformId = inject(PLATFORM_ID);
private readonly isBrowser = isPlatformBrowser(this.platformId);
private readonly signpostingService = inject(SignpostingService);

private readonly environment = inject(ENVIRONMENT);

Expand Down Expand Up @@ -304,6 +306,8 @@ export class PreprintDetailsComponent implements OnInit, OnDestroy {
this.actions.getPreprintProviderById(this.providerId());
this.fetchPreprint(this.preprintId());

this.signpostingService.addSignpostingHeaders();

this.dataciteService.logIdentifiableView(this.preprint$).pipe(takeUntilDestroyed(this.destroyRef)).subscribe();
}

Expand Down Expand Up @@ -413,6 +417,7 @@ export class PreprintDetailsComponent implements OnInit, OnDestroy {
givenName: contributor.givenName,
familyName: contributor.familyName,
})),
signpostingLinks: this.signpostingService.mockSignpostingLinks,
Copy link
Contributor

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 adding signpostingLinks to the metaTags object. I think my preference going forward would be to remove the signpostingLinks from the metaTags object (since this is going to be a <link> tag) and just have the logic for adding a <link> to the head tag done within the signpostingService.addSignpostingHeaders() function.

},
this.destroyRef
);
Expand Down
8 changes: 8 additions & 0 deletions src/app/shared/models/meta-tags/meta-tags-data.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -28,4 +35,5 @@ export interface MetaTagsData {
twitterCreator?: DataContent;
contributors?: DataContent;
keywords?: DataContent;
signpostingLinks?: SignpostingLink[];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: Similar to the above, I don't think the signpostingLinks needs to be in this metaTagsData interface

}
20 changes: 19 additions & 1 deletion src/app/shared/services/meta-tags.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { replaceBadEncodedChars } from '@osf/shared/helpers/format-bad-encoding.
import { MetadataRecordFormat } from '../enums/metadata-record-format.enum';
import { HeadTagDef } from '../models/meta-tags/head-tag-def.model';
import { MetaTagAuthor } from '../models/meta-tags/meta-tag-author.model';
import { Content, DataContent, MetaTagsData } from '../models/meta-tags/meta-tags-data.model';
import { Content, DataContent, MetaTagsData, SignpostingLink } from '../models/meta-tags/meta-tags-data.model';

import { MetadataRecordsService } from './metadata-records.service';

Expand Down Expand Up @@ -123,6 +123,11 @@ export class MetaTagsService {
this.prerenderReady.setNotReady();
const combinedData = { ...this.defaultMetaTags, ...metaTagsData };
const headTags = this.getHeadTags(combinedData);

if (metaTagsData.signpostingLinks) {
headTags.push(...this.getSignpostingLinkTags(metaTagsData.signpostingLinks));
}

of(metaTagsData.osfGuid)
.pipe(
switchMap((osfid) =>
Expand Down Expand Up @@ -231,6 +236,19 @@ export class MetaTagsService {
.filter((tag) => tag.attrs.content);
}

private getSignpostingLinkTags(signpostingLinks: SignpostingLink[]): HeadTagDef[] {
return signpostingLinks.map((link) => ({
type: 'link' as const,
attrs: {
rel: link.rel,
href: link.href,
...(link.type && { type: link.type }),
...(link.title && { title: link.title }),
class: this.metaTagClass,
},
}));
}

private buildMetaTagContent(name: string, content: Content): Content {
if (['citation_author', 'dc.creator'].includes(name) && typeof content === 'object') {
const author = content as MetaTagAuthor;
Expand Down
68 changes: 68 additions & 0 deletions src/app/shared/services/signposting.service.ts
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The 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(', ');
}
}