raannakasturi commited on
Commit
b80eb1d
·
1 Parent(s): 14fbe6d

Refactor generate_post_html function to enhance HTML structure and improve citation handling

Browse files
Files changed (1) hide show
  1. post_blog.py +47 -47
post_blog.py CHANGED
@@ -37,65 +37,65 @@ def generate_post_html(doi, title, category, summary, mindmap, citation):
37
  image = fetch_image(title, summary, imgbb_api_key)
38
  # svg_url = generate_mindmap_svg(title, mindmap)
39
  html_summary = mistune.html(summary)
40
- # post = f"""
41
- # <div id="paper_post">
42
- # <script src="https://cdn.jsdelivr.net/npm/markmap-autoloader"></script>
43
- # <script src="https://cdn.jsdelivr.net/npm/markmap-toolbar"></script>
44
- # <style>
45
- # .markmap {{
46
- # position: relative;
47
- # }}
48
- # .markmap > svg {{
49
- # width: 100%;
50
- # border: 2px solid #000;
51
- # height: 80dvh;
52
- # }}
53
- # </style>
54
- # <img style="display:block; width:100%; height:100%;" id="paper_image" src="{image.strip()}" alt="{title.strip()}">
55
- # <br>
56
- # <b>{{getToc}} $title={{Table of Contents}}</b>
57
- # <br>
58
- # <div id="paper_summary">
59
- # {html_summary.replace("&amp;", "&").strip()}
60
- # </div>
61
- # <br>
62
- # <h2>Mindmap</h2>
63
- # <p><small><em>If MindMap doesn't load, go to the <a href="/">Homepage</a> and visit blog again or <a href="/#">Switch to Android App (Under Development)</a>.</em></small></p>
64
- # <div class="markmap" id="paper_mindmap" data-markmap-url="{svg_url}">
65
- # <script type="text/template">
66
- # {mindmap.replace("&amp;", "&").replace(":", "=>").strip()}
67
- # </script>
68
- # </div>
69
- # <br>
70
- # <h2>Citation</h2>
71
- # <div id="paper_citation">
72
- # {mistune.html(citation.replace("&amp;", "&").strip())}
73
- # </div>
74
- # </div>
75
- # """
76
  post = f"""
77
- <div id="paper_post" data={doi}>
78
- <h1 id="paper_title">{title}</h1>
79
- <small><em>DOI: <a href="https://{doi}" target="_blank">{doi}</a></em></small>
80
- <em>Category: {category}</em>
81
- <br>
 
 
 
 
 
 
 
 
82
  <img style="display:block; width:100%; height:100%;" id="paper_image" src="{image.strip()}" alt="{title.strip()}">
83
  <br>
 
 
84
  <div id="paper_summary">
85
  {html_summary.replace("&amp;", "&").strip()}
86
  </div>
87
  <br>
88
  <h2>Mindmap</h2>
89
- <div id="paper_mindmap">
90
- {repr(mindmap.replace("&amp;", "&").strip())}
 
 
 
91
  </div>
92
  <br>
93
  <h2>Citation</h2>
94
  <div id="paper_citation">
95
- {citation.replace("&amp;", "&").strip()}
96
  </div>
97
  </div>
98
  """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99
  return post, image
100
 
101
  def create_post(doi, title, category, summary, mindmap, citation):
@@ -103,9 +103,9 @@ def create_post(doi, title, category, summary, mindmap, citation):
103
  post_category = f"{category}"
104
  try:
105
  post_body, post_image = generate_post_html(doi, title, category, summary, mindmap, citation)
106
- # with open('post.html', 'w') as f:
107
- # f.write(post_body)
108
- # exit(code=0)
109
  except Exception as e:
110
  print(f"Error generating post: {e}")
111
  return None, None, None, None
 
37
  image = fetch_image(title, summary, imgbb_api_key)
38
  # svg_url = generate_mindmap_svg(title, mindmap)
39
  html_summary = mistune.html(summary)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  post = f"""
41
+ <div id="paper_post">
42
+ <script src="https://cdn.jsdelivr.net/npm/markmap-autoloader"></script>
43
+ <script src="https://cdn.jsdelivr.net/npm/markmap-toolbar"></script>
44
+ <style>
45
+ .markmap {{
46
+ position: relative;
47
+ }}
48
+ .markmap > svg {{
49
+ width: 100%;
50
+ border: 2px solid #000;
51
+ height: 80dvh;
52
+ }}
53
+ </style>
54
  <img style="display:block; width:100%; height:100%;" id="paper_image" src="{image.strip()}" alt="{title.strip()}">
55
  <br>
56
+ <b>{{getToc}} $title={{Table of Contents}}</b>
57
+ <br>
58
  <div id="paper_summary">
59
  {html_summary.replace("&amp;", "&").strip()}
60
  </div>
61
  <br>
62
  <h2>Mindmap</h2>
63
+ <p><small><em>If MindMap doesn't load, go to the <a href="/">Homepage</a> and visit blog again or <a href="/#">Switch to Android App (Under Development)</a>.</em></small></p>
64
+ <div class="markmap" id="paper_mindmap" data-markmap-url="{{svg_url}}">
65
+ <script type="text/template">
66
+ {mindmap.replace("&amp;", "&").replace(":", "=>").strip()}
67
+ </script>
68
  </div>
69
  <br>
70
  <h2>Citation</h2>
71
  <div id="paper_citation">
72
+ {mistune.html(citation.replace("&amp;", "&").strip())}
73
  </div>
74
  </div>
75
  """
76
+ # post = f"""
77
+ # <div id="paper_post" data={doi}>
78
+ # <h1 id="paper_title">{title}</h1>
79
+ # <small><em>DOI: <a href="https://{doi}" target="_blank">{doi}</a></em></small>
80
+ # <em>Category: {category}</em>
81
+ # <br>
82
+ # <img style="display:block; width:100%; height:100%;" id="paper_image" src="{image.strip()}" alt="{title.strip()}">
83
+ # <br>
84
+ # <div id="paper_summary">
85
+ # {html_summary.replace("&amp;", "&").strip()}
86
+ # </div>
87
+ # <br>
88
+ # <h2>Mindmap</h2>
89
+ # <div id="paper_mindmap">
90
+ # {repr(mindmap.replace("&amp;", "&").strip())}
91
+ # </div>
92
+ # <br>
93
+ # <h2>Citation</h2>
94
+ # <div id="paper_citation">
95
+ # {citation.replace("&amp;", "&").strip()}
96
+ # </div>
97
+ # </div>
98
+ # """
99
  return post, image
100
 
101
  def create_post(doi, title, category, summary, mindmap, citation):
 
103
  post_category = f"{category}"
104
  try:
105
  post_body, post_image = generate_post_html(doi, title, category, summary, mindmap, citation)
106
+ with open('post.html', 'w') as f:
107
+ f.write(post_body)
108
+ exit(code=0)
109
  except Exception as e:
110
  print(f"Error generating post: {e}")
111
  return None, None, None, None