Pārlūkot izejas kodu

Highlight links to topic tag

master
The Dod 1 gadu atpakaļ
vecāks
revīzija
524ba6c550
1 mainītis faili ar 5 papildinājumiem un 1 dzēšanām
  1. 5
    1
      mymastotag.py

+ 5
- 1
mymastotag.py Parādīt failu

@@ -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 =[]

Notiek ielāde…
Atcelt
Saglabāt