Skip to content

Commit

Permalink
feat: support custom csp from transform
Browse files Browse the repository at this point in the history
  • Loading branch information
v8tenko committed Nov 5, 2024
1 parent 14a4cf5 commit d157975
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/transform/plugins/video/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export enum VideoService {
Yandex = 'yandex',
Vk = 'vk',
Rutube = 'rutube',
url = 'url',
}

export type Service = {
Expand All @@ -22,7 +23,7 @@ export type Service = {
export type Services = [VideoService, Service][];

export const defaults: VideoFullOptions = {
url: videoUrl,
videoUrl,
youtube: {width: 640, height: 390},
vimeo: {width: 500, height: 281},
vine: {width: 600, height: 600, embed: 'simple'},
Expand All @@ -31,4 +32,5 @@ export const defaults: VideoFullOptions = {
yandex: {width: 640, height: 390},
vk: {width: 640, height: 390},
rutube: {width: 640, height: 390},
url: {width: 640, height: 390},
};
3 changes: 2 additions & 1 deletion src/transform/plugins/video/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Process @[yandex](videoID)
// Process @[vk](videoID)
// Process @[rutube](videoID)
// Process @[url](fullLink)

import type MarkdownIt from 'markdown-it';
// eslint-disable-next-line no-duplicate-imports
Expand Down Expand Up @@ -77,7 +78,7 @@ function tokenizeVideo(md: MarkdownIt, options: VideoFullOptions): Renderer.Rend
: `<div class="embed-responsive embed-responsive-16by9"><iframe` +
` class="embed-responsive-item ${service}-player"` +
` type="text/html" width="${width}" height="${height}"` +
` src="${options.url(service, videoID, options)}"` +
` src="${options.videoUrl(service, videoID, options)}"` +
` frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe></div>`;
};
}
Expand Down
5 changes: 5 additions & 0 deletions src/transform/plugins/video/parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export function rutubeParser(url: string) {
return match ? match[1] : url;
}

const urlParser = (url: string) => url;

const supportedServices = Object.entries({
osf: {
extract: mfrParser,
Expand Down Expand Up @@ -82,6 +84,9 @@ const supportedServices = Object.entries({
'frame-src': 'https://rutube.ru/play/embed/',
},
},
url: {
extract: urlParser,
},
}) as Services;

export function parseVideoUrl(service: string, url: string) {
Expand Down
2 changes: 1 addition & 1 deletion src/transform/plugins/video/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type VideoServicesOptions = {
};

export type VideoFullOptions = VideoServicesOptions & {
url: VideoUrlFn;
videoUrl: VideoUrlFn;
};

export type VideoPluginOptions = Partial<VideoFullOptions>;
Expand Down
2 changes: 2 additions & 0 deletions src/transform/plugins/video/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export const videoUrl: VideoUrlFn = (service, videoID, options) => {
return `https://vk.com/video_ext.php?${videoID}`;
case 'rutube':
return `https://rutube.ru/play/embed/${videoID}`;
case 'url':
return videoID;
default:
return service;
}
Expand Down

0 comments on commit d157975

Please sign in to comment.