Added option whether to display images with <img> or <a>.
This commit is contained in:
		
							parent
							
								
									6de5347d71
								
							
						
					
					
						commit
						2771ec3ef8
					
				| @ -80,6 +80,7 @@ local_path_to_avatars="./avatars" # destination folder on pc | ||||
| [rss] | ||||
| enabled = true | ||||
| use_atom = false | ||||
| images_as_links = true # replace images with text-only links | ||||
| limit = 10 # include the most recent n posts | ||||
| title="Your Microblog Title Here" | ||||
| title_tagged = "#{__tagname__} on {__title__}" | ||||
|  | ||||
| @ -550,7 +550,7 @@ if __name__ == "__main__": | ||||
|         updated += writepage(tpl, tl, tc, cfg["page"],  | ||||
|             paginate=True if new_posts is None else False) | ||||
|         cfg["rss"]["accepted_images"] = cfg["post"]["accepted_images"] | ||||
|         cfg["rss"]["gallery_path"] = cfg["post"]["gallery"]["path_to_fullsize"] | ||||
|         cfg["rss"]["gallery"] = cfg["post"]["gallery"] | ||||
|         if cfg["rss"]["enabled"]: | ||||
|             # ensure output directory for feeds exists | ||||
|             if not os.path.exists("feeds"): | ||||
|  | ||||
							
								
								
									
										31
									
								
								src/rss.py
									
									
									
									
									
								
							
							
						
						
									
										31
									
								
								src/rss.py
									
									
									
									
									
								
							| @ -43,9 +43,10 @@ def _is_image_token(token: str, extensions): | ||||
| def enrich_msg( | ||||
|     lines, | ||||
|     accepted_images=[], | ||||
|     gallery_path="", | ||||
|     gallery_path=dict(), | ||||
|     trailing_punctuation="", | ||||
|     desc_len_limit=-1, | ||||
|     is_text_only = True | ||||
| ): | ||||
|     content = [] | ||||
|     parser = My_Html_Parser([]) | ||||
| @ -66,8 +67,16 @@ def enrich_msg( | ||||
|                     words[i] = new_word | ||||
|                 elif _is_image_token(core, accepted_images): | ||||
|                     suffix = word[len(core):] | ||||
|                     abs_url = urljoin(gallery_path, core) | ||||
|                     anchor = f"<a href=\"{escape(abs_url)}\">{escape(abs_url)}</a>" | ||||
|                     abs_url = urljoin(gallery_path["full"], core) | ||||
|                     foo_url = urljoin(gallery_path["thumb"], core) | ||||
| 
 | ||||
|                     href  = escape(abs_url) | ||||
|                     if is_text_only: | ||||
|                         atext = href | ||||
|                     else: | ||||
|                         atext = f"<img src=\"{foo_url}\">" | ||||
|                     anchor = f"<a href=\"{href}\">{atext}</a>" | ||||
| 
 | ||||
|                     new_word = anchor + suffix | ||||
|                     words[i] = new_word | ||||
|             words.insert(0,"<p>") | ||||
| @ -107,6 +116,17 @@ def write_feed(posts, filename, params, tagname=None): | ||||
|     base_url = l | ||||
|     TITLE_LEN_LIMIT = 60 | ||||
|     DESC_LEN_LIMIT = -1 if params["use_atom"] else 300 | ||||
| 
 | ||||
|     gpaths = dict() | ||||
|     img_path_full = urljoin( | ||||
|         params["url"], params["gallery"]["path_to_fullsize"] + "/" | ||||
|     ) | ||||
|     gpaths["full"]  = img_path_full | ||||
|     img_path_thumb = urljoin( | ||||
|         params["url"], params["gallery"]["path_to_thumb"] + "/" | ||||
|     ) | ||||
|     gpaths["thumb"] = img_path_thumb | ||||
| 
 | ||||
|     for post in posts: | ||||
|         # len of post.message is number of lines | ||||
|         msg = post.message | ||||
| @ -115,12 +135,11 @@ def write_feed(posts, filename, params, tagname=None): | ||||
|         de = " ".join( | ||||
|             enrich_msg( | ||||
|                 msg, | ||||
|                 gallery_path=urljoin( | ||||
|                     params["url"], params.get("gallery_path", "") + "/" | ||||
|                 ), | ||||
|                 gallery_path=gpaths, | ||||
|                 accepted_images=params["accepted_images"], | ||||
|                 trailing_punctuation=params["trailing_punctuation"], | ||||
|                 desc_len_limit=DESC_LEN_LIMIT, | ||||
|                 is_text_only = params["images_as_links"] | ||||
|             ) | ||||
|         ) | ||||
|         li = base_url + ("#%i" % post.num) | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user