def gen_catalog(posts_dir, output_file, headers, footers): articles, _ = load_mds("./articles") with open(output_file, "w+") as f: # clear all the contents in file f.truncate() for header in headers: f.write(header) f.write("\n\n") # write catalog for title, date, filename, path in articles: f.write( "- {date} - [{title}](https://jiajunhuang.com/{path}/{filename}.html)\n" .format( date=date.strftime("%Y/%m/%d"), title=title, path=path, filename=filename, )) for footer in footers: f.write(footer) f.write("\n\n")
redirect, send_from_directory, make_response, ) import markdown import sentry_sdk from utils import load_mds if os.getenv("SENTRY_DSN" ): # if dsn := os.getenv("xxx"); dsn != "" {} is nice in here... sentry_sdk.init(os.getenv("SENTRY_DSN")) app = Flask(__name__) articles = load_mds("./articles") hackers = load_mds("./hackers") def read_article(filename): return read_md("./articles", filename) def read_hacker(filename): return read_md("./hackers", filename) def read_md(directory, filename): with open(os.path.join(directory, filename)) as f: title = f.readline() content = title + f.read()
from utils import load_mds from config import config from models import ( get_session, Issue, Note, ) app = Flask(__name__) logging.basicConfig(level=logging.INFO) if config.SENTRY_DSN: logging.info("integrated sentry...") sentry_sdk.init(dsn=config.SENTRY_DSN, integrations=[FlaskIntegration()]) articles, words = load_mds("./articles") # title, datetime, filename, folder all_articles = sorted(articles, key=lambda i: (i[1], i[0], i[2]), reverse=True) SUBTITLE_MAP = { "golang": "Golang 教程", "python": "Python 教程", } @functools.lru_cache() def get_words(top=35): return words.most_common(top) # functions can be executed in jinja