def get_feed_from_notes(notes): sitemap = '' rss2 = '' atom = '' name = User.get_user_info('name') email = User.get_user_info('email') root_url = Config.get('url') timezone = Config.get('timezone') # TODO: note_url_prefix 설정 적용 note_url_prefix = 'note' for i, note in enumerate(notes): path = quote(note.path) item_url = f'{root_url}/{note_url_prefix}/{path}' # sitemap updated_iso = format_datetime(note.updated, style='iso-8601', timezone=timezone) sitemap += f' <url>\n' sitemap += f' <loc>{item_url}</loc>\n' sitemap += f' <lastmod>{updated_iso}</lastmod>\n' sitemap += f' </url>\n' if i > 10: continue # rss updated_rfc = format_datetime(note.updated, style='rfc-822', timezone=timezone) rss2 += f' <item>\n' rss2 += f' <title>{note.title}</title>\n' rss2 += f' <author>{email} ({name})</author>\n' rss2 += f' <pubDate>{updated_rfc}</pubDate>\n' rss2 += f' <link>{item_url}</link>\n' rss2 += f' <guid isPermaLink="false">{item_url}</guid>\n' rss2 += f' <description>{note.summary}</description>\n' rss2 += f' </item>\n' # atom published_iso = format_datetime(note.created, style='iso-8601', timezone=timezone) atom += f' <entry>\n' atom += f' <title>{note.title}</title>\n' atom += f' <id>{item_url}</id>\n' atom += f' <link rel="alternate" href="{item_url}" />\n' atom += f' <published>{published_iso}</published>\n' atom += f' <updated>{updated_iso}</updated>\n' atom += f' <summary>{note.summary}</summary>\n' atom += f' </entry>\n' return sitemap, rss2, atom
def get_base_meta(): note_config = Config.get() meta = dict() meta['note_title'] = note_config.get('note_title', '') meta['note_subtitle'] = note_config.get('note_subtitle', '') meta['note_description'] = note_config.get('note_description', '') meta['user_name'] = User.get_user_info('name') meta['year'] = datetime.now().year meta['ga_tracking_id'] = note_config.get('ga_tracking_id') meta['logged_in'] = User.is_logged_in() return meta
def update_atom(atom_items, build_date): config = Config.get() user = User.get_user_info() atom = '' atom += XML_Declaration atom += f'<feed xmlns="http://www.w3.org/2005/Atom">\n' atom += f' <title>{config["note_title"]}</title>\n' atom += f' <subtitle>{config["note_subtitle"]}</subtitle>\n' atom += f' <author>\n' atom += f' <name>{user["name"]}</name>\n' atom += f' <email>{user["email"]}</email>\n' atom += f' </author>\n' atom += f' <updated>{build_date}</updated>\n' atom += f' <id>{config["url"]}/</id>\n' atom += f' <link rel="alternate" href="{config["url"]}" />\n' atom += f' <link rel="self" href="{config["url"]}/atom" />\n' atom += f' <generator>ipari-note</generator>' atom += atom_items atom += f'</feed>' path = os.path.join(current_app.instance_path, 'atom.xml') with open(path, 'w', encoding='utf-8') as f: f.write(atom)