-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added schema to organization pages (#777)
Added JSON-LD schema to organization pages (SEAB-85)
- Loading branch information
Showing
7 changed files
with
98 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
2 changes: 1 addition & 1 deletion
2
...ganization/update-organization-description/update-organization-description.component.html
This file contains 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 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,33 @@ | ||
import { inject, TestBed } from '@angular/core/testing'; | ||
import { Organization } from './openapi'; | ||
import { OrgSchemaService } from './org-schema.service'; | ||
|
||
describe('OrgSchemaService', () => { | ||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
providers: [OrgSchemaService] | ||
}); | ||
}); | ||
|
||
it('should be created', inject([OrgSchemaService], (service: OrgSchemaService) => { | ||
expect(service).toBeTruthy(); | ||
})); | ||
it('should have expected attributes', inject([OrgSchemaService], (service: OrgSchemaService) => { | ||
const org: Organization = { | ||
name: 'org', | ||
link: 'http://org.org', | ||
avatarUrl: 'http://org.org/image', | ||
email: '[email protected]' | ||
}; | ||
const schema = service.getSchema(org); | ||
expect(schema.name).toEqual('org'); | ||
expect(schema.url).toEqual('http://org.org'); | ||
expect(schema.logo).toEqual('http://org.org/image'); | ||
expect(schema.contactPoint).toEqual([{ '@type': 'ContactPoint', email: '[email protected]' }]); | ||
})); | ||
it('should handle null organization', inject([OrgSchemaService], (service: OrgSchemaService) => { | ||
const org: Organization = null; | ||
const schema = service.getSchema(org); | ||
expect(schema).toBeNull(); | ||
})); | ||
}); |
This file contains 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,48 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Organization } from './openapi'; | ||
|
||
export interface OrganizationSchema { | ||
'@context': string; | ||
'@type': string; | ||
contactPoint?: Array<ContactPoint>; | ||
description?: string; | ||
location?: string; | ||
logo?: string; | ||
name: string; | ||
url: string; | ||
} | ||
|
||
export interface ContactPoint { | ||
// Represents the contact email displayed on the organization page | ||
'@type': string; | ||
email: string; | ||
} | ||
|
||
@Injectable() | ||
export class OrgSchemaService { | ||
constructor() {} | ||
getSchema(org: Organization): OrganizationSchema | null { | ||
if (!org) { | ||
return null; | ||
} | ||
const schema: OrganizationSchema = { | ||
'@context': 'http://schema.org', | ||
'@type': 'Organization', | ||
name: org.name, | ||
url: org.link | ||
}; | ||
if (org.avatarUrl) { | ||
schema.logo = org.avatarUrl; // image link | ||
} | ||
if (org.description) { | ||
schema.description = org.description; | ||
} | ||
if (org.email) { | ||
schema.contactPoint = [{ '@type': 'ContactPoint', email: org.email }]; | ||
} | ||
if (org.location) { | ||
schema.location = org.location; | ||
} | ||
return schema; | ||
} | ||
} |