-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for embedded content (iframes & gists)
Signed-off-by: Sphericalkat <[email protected]>
- Loading branch information
1 parent
03b74fd
commit 7efffe6
Showing
4 changed files
with
53 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,7 @@ html, body { | |
line-height: 1.7777778; | ||
} | ||
} | ||
|
||
.gist tbody tr { | ||
border: none !important; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package converters | ||
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
"strings" | ||
|
||
"github.com/medium.rip/pkg/entities" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
func ConvertEmbedded(media entities.MediaResource) string { | ||
if media.IframeSrc == "" { | ||
return customEmbed(media) | ||
} else { | ||
return fmt.Sprintf("<iframe src=\"%s\" width=\"%d\" height=\"%d\" frameborder=\"0\" allowfullscreen=\"true\" ></iframe>", media.IframeSrc, media.IframeWidth, media.IframeHeight) | ||
} | ||
} | ||
|
||
func customEmbed(media entities.MediaResource) string { | ||
if strings.HasPrefix(media.Href, "https://gist.github.com") { | ||
return fmt.Sprintf("<script src=\"%s.js\"></script>", media.Href) | ||
} else { | ||
url, err := url.Parse(media.Href) | ||
var caption string | ||
if err != nil { | ||
log.Warnf("Error parsing url %s", media.Href) | ||
caption = media.Href | ||
} else { | ||
caption = fmt.Sprintf("Embedded content at %s", url.Host) | ||
} | ||
return fmt.Sprintf("<figure><a href=\"%s\">%s</a></figure>", media.Href, caption) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters