Skip to content

Instantly share code, notes, and snippets.

@shumiyao
Last active February 9, 2023 23:27
Show Gist options
  • Save shumiyao/3b597864fd40bbcc7d2756f690281910 to your computer and use it in GitHub Desktop.
Save shumiyao/3b597864fd40bbcc7d2756f690281910 to your computer and use it in GitHub Desktop.
Shortcode Test for StaticCMS (warning: this is a work in progress and incomplete)
interface TestShortcodeProps {
src: string;
}
CMS.registerShortcode<TestShortcodeProps>('test', {
label: 'test',
openTag: '[',
closeTag: ']',
separator: '|',
toProps: (args) => {
if (args.length > 0) {
return { src: args[0] };
}
return { src: '' };
},
toArgs: ({ src }) => {
return [src];
},
control: (test) => {
const { controlProps, onChange, src } = test;
function handleChange(event) {
const [file] = event.target.files;
onChange({ src: URL.createObjectURL(file) });
}
return (
<>
<span>
<input key='control-input' id='test' value='' type='file' onChange={handleChange} />
</span>
<div key='control-preview'>
<img src={src} />
</div>
</>
);
},
preview: ({ src }) => {
return h(
'span',
{},
h(
'iframe',
{
width: '420',
height: '315',
src: `https://www.youtube.com/embed/${src}`,
},
''
)
);
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment