Skip to content

Commit

Permalink
fix: Keep content-type when using metadata templates
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimvh committed Feb 14, 2024
1 parent a9bcc96 commit 43a5437
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/pods/generate/BaseResourcesGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ export class BaseResourcesGenerator implements TemplatedResourcesGenerator {
// Add metadata from .meta file if there is one
if (metaLink) {
const rawMetadata = await this.generateMetadata(metaLink, options);
if (!rawMetadata.contentType) {
// Make sure this does not remove the content-type if none is explicitly defined
rawMetadata.contentType = metadata.contentType;
}
const metaIdentifier = this.metadataStrategy.getAuxiliaryIdentifier(link.identifier);
const descriptionMeta = new RepresentationMetadata(metaIdentifier);
addResourceMetadata(rawMetadata, isContainerIdentifier(link.identifier));
Expand Down
5 changes: 5 additions & 0 deletions test/unit/pods/generate/BaseResourcesGenerator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { asyncToArray } from '../../../../src/util/IterableUtil';
import { ensureTrailingSlash, joinFilePath, trimTrailingSlashes } from '../../../../src/util/PathUtil';
import { readableToQuads, readableToString } from '../../../../src/util/StreamUtil';
import { HandlebarsTemplateEngine } from '../../../../src/util/templates/HandlebarsTemplateEngine';
import { CONTENT_TYPE_TERM } from '../../../../src/util/Vocabularies';
import { SimpleSuffixStrategy } from '../../../util/SimpleSuffixStrategy';
import { mockFileSystem } from '../../../util/Util';

Expand Down Expand Up @@ -144,6 +145,10 @@ describe('A BaseResourcesGenerator', (): void => {
const expDocMetadataQuads = docMetadataQuads.getQuads(docMetadata.identifier, 'pre:has', null, null);
expect(expDocMetadataQuads).toHaveLength(1);
expect(expDocMetadataQuads[0].object.value).toBe('metadata');
// Metadata will replace existing metadata so need to make sure content-type is still there
const contentDocMetadataQuads = docMetadataQuads.getQuads(docMetadata.identifier, CONTENT_TYPE_TERM, null, null);
expect(contentDocMetadataQuads).toHaveLength(1);
expect(contentDocMetadataQuads[0].object.value).toBe('text/turtle');
});

it('does not create container when it already exists.', async(): Promise<void> => {
Expand Down

0 comments on commit 43a5437

Please sign in to comment.