1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-04-27 13:56:22 -04:00

iframe shortcode for valid AMP

This commit is contained in:
Jake Jarvis 2020-04-30 07:53:08 -04:00
parent 6854129108
commit 35bfbb517c
Signed by: jake
GPG Key ID: 2B0C9CF251E69A39
5 changed files with 15 additions and 3 deletions

View File

@ -9,7 +9,7 @@ tags:
- How To
- Tutorial
css: |
div#content iframe#example {
div#content div.embed iframe {
height: 200px;
width: 100%;
max-width: 650px;
@ -38,13 +38,13 @@ I've written a simple implementation below, which...
...meaning that any CSS selectors beginning with `body.dark` or `body.light` will only apply when the respective mode is active. A good place to start is by separating any color rules --- your background, text, links, etc. --- into a different section of your CSS. Using [SASS or SCSS](https://sass-lang.com/) makes this a whole lot [easier with nesting](https://sass-lang.com/guide#topic-3) but is not required; this was written with a [KISS](https://getyarn.io/yarn-clip/embed/eed08f4f-d1c9-4cc0-b041-f280a5dbf0a5?autoplay=false) mentality.
<iframe id="example" src="https://jakejarvis.github.io/dark-mode-example/"></iframe>
{{< iframe src="https://jakejarvis.github.io/dark-mode-example/" width="650" height="200" >}}
A _very_ barebones example is embedded above ([view the source here](https://github.com/jakejarvis/dark-mode-example)) or you can try it out on this site by clicking the 💡 lightbulb in the upper right corner of this page. You'll notice that the dark theme sticks when refreshing this page, navigating between other pages, or if you were to return to this example weeks from now.
---
### Minified JS (392 bytes gzipped 📦):
### Minified JS: (392 bytes gzipped 📦)
```js
/*! Dark mode switcheroo | MIT License | jrvs.io/darkmode */

View File

@ -0,0 +1,7 @@
<amp-iframe
sandbox="allow-scripts allow-same-origin"
layout="responsive"
width="{{ .Get "width" }}"
height="{{ .Get "height" }}"
src="{{ .Get "src" }}">
</amp-iframe>

View File

@ -0,0 +1 @@
iframe.html

View File

@ -0,0 +1,3 @@
<div class="embed iframe">
<iframe src="{{ .Get "src" }}"></iframe>
</div>

View File

@ -0,0 +1 @@
iframe.html