Commit Graph

5 Commits

Author SHA1 Message Date
Edward Loveall f05a12a880
Add support for missing posts
Posts, like 8661f4724aa9, can go missing if the account or post was
removed. In this case, the API returns data like this:

```json
{
  "data": {
    "post": null
  }
}
```

When this happens, we can detect it because the parsed response now has
a nil value: `response.data.post == nil` and construct an `EmptyPage`
instead of a `Page`. The `Articles::Show` action can then render
conditionally based on if the response from `PageConverter` is a `Page`
or an `EmptyPage`.
2022-06-17 16:00:01 -04:00
Edward Loveall aacef34a14
Accept all known medium post path types
Including:

* https://example.com/my-cool-post-123456abcdef
* https://example.com/123456abcdef
* https://medium.com/@user/my-cool-post-123456abcdef
* https://medium.com/user/my-cool-post-123456abcdef
* https://medium.com/p/my-cool-post-123456abcdef
* https://medium.com/posts/my-cool-post-123456abcdef
* https://medium.com/p/123456abcdef

Replace any of those posts with the scribe domain and it should resolve
2021-10-03 16:45:20 -04:00
Edward Loveall e64e9f0853
Use href from iframe media response
Turns out, href exists in the mediaResponse query. I can use that
instead of fetching that separately.
2021-08-08 16:49:02 -04:00
Edward Loveall 5a5f68bcf8
First step rendering a page
The API responds with a bunch of paragraphs which the client converts
into Paragraph objects.

This turns the paragraphs in a PostResponse's Paragraph objects into the
form needed to render them on a page. This includes converting flat list
elements into list elements nested by a UL. And adding a limited markups
along the way.

The array of paragraphs is passed to a recursive function. The function
takes the first paragraph and either wraps the (marked up) contents in a
container tag (like Paragraph or Heading3), and then moves onto the next
tag. If it finds a list, it starts parsing the next paragraphs as a list
instead.

Originally, this was implemented like so:

```crystal
paragraph = paragraphs.shift
if list?
  convert_list([paragraph] + paragraphs)
end
```

However, passing the `paragraphs` after adding it to the already shifted
`paragraph` creates a new object. This means `paragraphs` won't be
mutated and once the list is parsed, it starts with the next element of
the list. Instead, the element is `shift`ed inside each converter.

```crystal
if paragraphs.first == list?
  convert_list(paragraphs)
end

def convert_list(paragraphs)
  paragraph = paragraphs.shift
  # ...
end
```

When rendering, there is an Empty and Container object. These represent
a kind of "null object" for both leafs and parent objects respectively.
They should never actually render. Emptys are filtered out, and
Containers are never created explicitly but this will make the types
pass.

IFrames are a bit of a special case. Each IFrame has custom data on it
that this system would need to be aware of. For now, instead of trying
to parse the seemingly large number of iframe variations and dealing
with embedded iframe problems, this will just keep track of the source
page URL and send the user there with a link.
2021-07-04 16:28:03 -04:00
Edward Loveall fcf3eb14d0
Initial app 2021-05-01 17:03:38 -04:00