Skip to content

Commit ada55f9

Browse files
update social links
1 parent a3bc484 commit ada55f9

File tree

102 files changed

+851
-127
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+851
-127
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
__pycache__/
1+
**/__pycache__
2+
**/.DS_Store

build.py

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
SOCIAL = (
9393
(f"{AUTHOR} on GitHub", f"https://github.com/{AUTHOR}"),
9494
(f"{AUTHOR} on YouTube", f"https://youtube.com/@{AUTHOR}"),
95+
(f"{AUTHOR} on Instagram", f"https://instagram.com/{AUTHOR}/"),
9596
)
9697

9798
MENUITEMS = (
@@ -162,37 +163,40 @@ def schemascii_fence(source, lang, cls, opts, md, attrs, **kwargs):
162163
return f"<code style=\"color: red\">Schemascii error:\n{err!r}</code>"
163164

164165

165-
class YTExt(Extension):
166+
class SocialExtension(Extension):
166167
def extendMarkdown(self, md):
167-
md.postprocessors.register(YoutubeEmbed(md), "youtube", -1)
168+
md.postprocessors.register(SocialEmbed(md), "social", -1)
168169

169170

170-
class YoutubeEmbed(Postprocessor):
171+
class SocialEmbed(Postprocessor):
171172
def run(self, src: str):
172-
if "<youtube" not in src:
173+
# cSpell: ignore insta
174+
if "<youtube" not in src and "<insta" not in src:
173175
return src
174176
# Seems like a kludge to not use a Treeprocessor.
175-
# But I tried, it doesn't work. ¯\_(ツ)_/¯ Weird
177+
# But I tried, it doesn't work. ¯\_(ツ)_/¯ Weird!
176178
# And you can't use xml.etree.ElementTree either
177179
# because it's *cough cough* not valid XML...
178-
magic = YoutubeMagic()
180+
magic = SocialMagic()
179181
magic.feed(src)
180182
magic.close()
181183
return magic.out
182184

183185

184-
class YoutubeMagic(html.parser.HTMLParser):
186+
class SocialMagic(html.parser.HTMLParser):
185187
def __init__(self):
186188
super().__init__(convert_charrefs=False)
187189
self.out = ""
188190

189-
def handle_starttag(self, tag: str, attrs: dict[str, str]):
190-
if tag != "youtube":
191+
def handle_starttag(self, tag: str, attrs: list[tuple[str, str]]):
192+
func = getattr(self, "handle_" + tag, None)
193+
if not callable(func):
191194
self.out += self.get_starttag_text()
192-
return
193-
# why is it not a dictionary??
194-
attrs = dict(attrs)
195-
# munge the tag to make it an embed
195+
else:
196+
self.out += func(dict(attrs))
197+
handle_startendtag = handle_starttag
198+
199+
def handle_youtube(self, attrs: dict[str, str]) -> str:
196200
if "short" in attrs:
197201
url = "https://youtube.com/embed/" + attrs["short"]
198202
ratio = "9/16"
@@ -227,13 +231,25 @@ def handle_starttag(self, tag: str, attrs: dict[str, str]):
227231
"web-share"),
228232
"allowfullscreen": True}
229233

230-
self.out += f"<iframe{"".join(f" {k}=\"{v}\"" for k,
231-
v in attrs.items())}></iframe>"
232-
233-
handle_startendtag = handle_starttag
234-
235-
def handle_endtag(self, tag):
236-
if tag != "youtube":
234+
return f"<iframe{"".join(f" {k}=\"{v}\"" for k,
235+
v in attrs.items())}></iframe>"
236+
237+
def handle_instagram(self, attrs: dict[str, str]) -> str:
238+
permalink = html.escape(f"https://www.instagram.com/p/{
239+
attrs["post"]}/?utm_source=ig_embed&utm_campaign=loading")
240+
# cSpell: ignore instgrm
241+
return f"""<blockquote class="instagram-media"{
242+
"" if not bool(attrs.get("caption", True))
243+
else " data-instgrm-captioned"}
244+
data-instgrm-permalink="{permalink}"
245+
data-instgrm-version="14">
246+
<a href="{permalink}">View this post on Instagram</a>
247+
</blockquote>""".replace("\n", "")
248+
handle_insta = handle_instagram
249+
250+
def handle_endtag(self, tag: str):
251+
func = getattr(self, "handle_" + tag, None)
252+
if not callable(func):
237253
self.out += f"</{tag}>"
238254

239255
def handle_data(self, data):
@@ -310,7 +326,7 @@ def handle_charref(self, ref):
310326
"syntax_left": r"<{2,}\s+i(?:nc(?:lude))",
311327
"syntax_right": r">{2,}",
312328
},
313-
"build:YTExt": {},
329+
"build:SocialExtension": {},
314330
},
315331
"output_format": "html5",
316332
}

docs/2021/updating-python/index.html

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/2022/airdrop-for-non-apple-users/index.html

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/2022/almost-no-javascript/index.html

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/2022/change-of-plans/index.html

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/2022/debugger-almost/index.html

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/2022/first-pull-request/index.html

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/2022/gah-i-broke-it/index.html

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/2022/how-i-came-up-with-phoo/index.html

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy