Commit graph

11 commits

Author SHA1 Message Date
Edward Loveall
7cda16cef1
Show the host for the iframe link
Instead of showing only: Click to visit embedded content

An embedded link now displays with the domain it's linking to: Embedded
content at example.com

This hopefully breaks up the links a bit so it'e easier to distinguish
between a bunch of them in a row (as long as they are on different
domains).
2021-07-05 15:36:38 -04:00
Edward Loveall
d863cc27a5
Fetch the resized image
Instead of getting the full size image, the image can be fetched with a
width and height parameter so that only the resized data is
transferred. The url looks like this:

https://cdn-images-1.medium.com/fit/c/<width>/<height>/<media-id>

I picked a max image width of 800px. If the image width is more than
that, it scales the width down to 800, then applies that ratio to the
height. If it's smaller than that, the image is displayed as the
original.
2021-07-05 14:56:10 -04:00
Edward Loveall
f7a72fd2b5
Render image inside a figure with a caption
Most images have a caption (or at least have the option of being
captioned). Instead of displaying the raw image, it's not rendered
inside a <figure> tag with a <figcaption> (possibly blank) as a
sibling. The <figcaption> can be marked up with links.
2021-07-05 14:56:10 -04:00
Edward Loveall
743d9e5fa9
Render a User Anchor 2021-07-04 17:37:45 -04:00
Edward Loveall
bc356baa45
Render a Link Anchor
As opposed to a user anchor
2021-07-04 17:28:19 -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
fe2f3ebe80
Add test script
This makes it much easier to randomize the spec order
2021-07-04 16:03:25 -04:00
Edward Loveall
57f26996b2
Break up views into components 2021-05-15 17:06:42 -04:00
Edward Loveall
c954fc1006
Move response types to models 2021-05-15 17:05:28 -04:00
Edward Loveall
9e96f29852
Add basic response (except images)
The basic idea here is to fetch the post with the medium API, parse the
JSON into types, and then re-display the content. We also have to fetch
each media object as a REST call to get things like embeded iframes.
2021-05-01 17:39:05 -04:00
Edward Loveall
fcf3eb14d0
Initial app 2021-05-01 17:03:38 -04:00