-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Prismic V2 format #17
base: master
Are you sure you want to change the base?
Conversation
Hi! I'll try to take a look at it next week at best. |
Hey @jaen, I've tried using the 1) Links are not renderedThis tool returns a JSON slightly different to what Slice Simulator does. Example link from {
"content": {
"spans": [
{
"end": 61,
"start": 53,
"type": "em"
},
{
"data": {
"url": "https://github.com/prismicio/kramdown-prismic"
},
"end": 82,
"start": 76,
"type": "hyperlink"
},
{
"end": 16,
"start": 8,
"type": "strong"
}
],
"text": "This is markdown that will be converted to Prismic's RichText format, using a fork of the kramdown-prismic ruby gem."
},
"type": "paragraph"
} where Slice Simulator generates:
The only missing keys are 2) When using images, Slice Simulator fails to render the whole field. It shows the field as empty:The output from the script was: {
"content": {
"spans": [
],
"text": ""
},
"data": {
"alt": "un alt",
"origin": {
"url": "https://images.unsplash.com/photo-1546548970-71785318a17b?crop=entropy&cs=srgb&fm=jpg&ixid=M3wzMzc0NjN8MHwxfHNlYXJjaHwxfHxjaXRydXMlMjBmcnVpdHxlbnwwfHx8fDE3MDkwODAzMzd8MA&ixlib=rb-4.0.3&q=85"
}
},
"type": "image"
} while Slice Simulator generates:
3) Horizontal lines and HTML tags are ignoredIs there a way to workaround this? These things can be only a problem with the simulator itself and maybe the format is fine, but since we can't use the API, I think it's the only wait for us to test it. |
@afska as far as I understand the Migration API and the editor use a somewhat different format, so it might be the source of issues – that said, if you could give me the documents you use to test this (markdown, I assume) I can try testing this on my end and fix any problems that arise.
I have only maintained parity with what the tool does right now, and it ignores most of the tags. This is probably related to the fact, that Prismic's rich text seems to have a limited selection of elements – as far as I can see there's only equivalents of |
@jaen ah, I see, thx. So, there's no way to display custom HTML in Prismic? I'm working on a migration that contains multiple markdown files, and we don't know whether they use inline HTML tags inside the markdown, so I was hoping there was a way to migrate these files as close to 1:1 as possible. Here's the markdown file I used to test. |
@afska it seems like it to me – but keep in mind as a fresh contractor I'm nowhere near being an authoritative source, customer support forum (https://community.prismic.io/) would be a better bet. Thanks for the markdown file, I'll take a look at it when I have a moment. |
@afska I was told you're in touch with someone from support, so if there's anything else that comes up that's not PR-related, I hope you won't mind if I'll respond via the support person as not to derail the PR. But since I'm already posting a comment:
|
EDIT: Dismiss this message. I wasn't testing correctly. Hey @jaen, thanks for your responses. I returned with more feedback! (this time more related to the PR) So I tried the Migration API and yeah, it works pretty well. I didn't face any of the issues I commented before. It seems though that your code outputs objects like Another issue is that hyperlinks need to contain the key We implemented this workaround to address the issues and wanted to ensure you were aware of these adjustments. _adapt(richText) {
return richText.map((part) => {
if (part.content) part = { ...part, ...part.content, content: undefined };
if (part.spans) {
for (let span of part.spans) {
if (span.type === "hyperlink" && span.data != null)
span.data.link_type = "Web";
}
}
return part;
});
} |
@afska hey, sorry for not getting back earlier, but I had some other tasks to focus on. Anyway, I can't seem to reproduce what you described, when calling it like this:
Note the |
@jaen ah, that's probably it then, sorry. I was not sending the format flag. |
The `:origin` field of the image was not being converted according to the API V2 representation. This is now corrected.
When writing example code for the Migration API I came across a slight inaccuracy in the V2 format with the @francois2metz FYI I was given to understand that Prismic's import/export feature is planned to go away by the end of this month. As such it would probably be useful if there's an official version of this gem supporting API V2. So if you could spare some time for a review, it would be appreciated It seems that there's a |
@aadtyaraj01 yeah, it was an issue in how you called the script in your shell, not the script itself. But I agree that the current interface – passing the script as a parameter, not as a file path – is kind of awkward and I think it could be improved. But ultimately up to @francois2metz how he wants the CLI to look (and maybe would be a separate PR anyway)> @seppviljar weird – I'll look at it as soon as I can and I'll respond when I understand the problem. |
Hello,
On behalf of Prismic, I come bearing this PR adding support for the new rich text JSON format used the V2 API (e.g. the Migration API). As an outside contractor who's rather fresh to the team, I can't claim I haven't missed some format subtlety, but I've tried my best not to and the updated tool's output was also verified internally. None the less, please also double-check on your end, if you are able.
I think this should be mostly ready for review – there's only an outstanding question of the CLI interface.
Currently, the tool takes the first CLI argument as the text to convert, which is a bit of a weird choice (as you have to do
"$(cat some/file)"
to take input from a file), but generally works. But, adding the V2 format and not wanting to break the existing V1 functionality, I have usedoptparse
to add a--format v2
switch, which had an unexpected side-effect of having dashes in the text-to-convert confusing the parser into thinking they are arguments, thus forcing usage of--
to separate the text from the rest of arguments.Given that adding format choice parameter can already break compatibility with existing usages of the tool, what do you think about leaving the existing CLI entry points in
bin
as-is and instead add new one, sayprismic-convert
(orkramdown-prismic
or whatever, name to bikeshed) that has a more convetional interface instead, for example:What do you think about that?
There's also a few notes that might help you whjen reviewing:
FormatUtils::V2
itself, I can add that if you wish,convert_a
can be called not only for images - for example toplevel anchors also trigger that method and the CLI blows up. I have not fixed it, but I can if you want,linkTo
the way you use it - I haven't added any warnings about it, nor changed code to remove it, should I,"string"
all the time and{:a => b}
over{a: b}
– I have tried to match what was already there, but might have slipped to my default unwittingly and it seems there's no linting set up, so let me know if I messed up.I think that's all that comes to my mind now, hopefully the PR's not too terrible.