瀏覽代碼

Highlight links to topic tag

master
The Dod 1 年之前
父節點
當前提交
524ba6c550
共有 1 個檔案被更改,包括 5 行新增1 行删除
  1. 5
    1
      mymastotag.py

+ 5
- 1
mymastotag.py 查看文件

@@ -19,12 +19,16 @@ def my_masto_tag(lang, instance, user, tag):
19 19
     title = f'@{user}@{instance} — #{tag}'
20 20
     og_image = None
21 21
     feed = feedparser.parse(f'https://{instance}/@{user}/tagged/{tag}.rss')
22
+    hashtag = '#' + tag.lower()
22 23
     for e in feed['entries']:
23 24
         e['date'] = time.strftime('%Y-%m-%d', e['published_parsed'])
24 25
         soup = BeautifulSoup(e['description'], 'html.parser')
25 26
         for link in soup.find_all('a'):
26 27
             link['target'] = '_blank'
27
-            link['class'] = ['link-info', 'text-decoration-none']
28
+            if link.text.lower()==hashtag:
29
+                link['class'] = ['badge', 'bg-info', 'text-decoration-none']
30
+            else:
31
+                link['class'] = ['link-info', 'text-decoration-none']
28 32
         e['description'] = str(soup)
29 33
         images = []
30 34
         videos =[]

Loading…
取消
儲存