Print this page


Split Close
Expand all
Collapse all
          --- old/post.c
          +++ new/post.c
   1    1  /*
   2    2   * Copyright (c) 2009-2020 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
        3 + * Copyright 2020, Kebe Software & Services
   3    4   *
   4    5   * Permission is hereby granted, free of charge, to any person obtaining a copy
   5    6   * of this software and associated documentation files (the "Software"), to deal
   6    7   * in the Software without restriction, including without limitation the rights
   7    8   * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
   8    9   * copies of the Software, and to permit persons to whom the Software is
   9   10   * furnished to do so, subject to the following conditions:
  10   11   *
  11   12   * The above copyright notice and this permission notice shall be included in
  12   13   * all copies or substantial portions of the Software.
↓ open down ↓ 222 lines elided ↑ open up ↑
 235  236  
 236  237  static int __do_load_post_body_fmt2(struct post *post, struct str *html)
 237  238  {
 238  239          str_putref(post->body); /* free the previous */
 239  240          post->body = str_getref(html);
 240  241          ASSERT(post->body);
 241  242  
 242  243          return 0;
 243  244  }
 244  245  
      246 +static int
      247 +__do_load_post_body_fmt4(struct post *post, const struct str *md)
      248 +{
      249 +        /*
      250 +         * Like HTML, assume the .lisp file contains all of the other post
      251 +         * metadata.  If that assumption changes, update here.
      252 +         *
      253 +         * Unlike HTML, we plan to provide a clean error string if MD
      254 +         * parsing fails.
      255 +         */
      256 +        str_putref(post->body); /* Free the previous text. */
      257 +        post->body = fmt4_md_to_html(md);
      258 +        if (post->body == NULL) {
      259 +                /*
      260 +                 * XXX KEBE SAYS do something clever here with a small HTML
      261 +                 * string.  For now, panic.
      262 +                 */
      263 +                ASSERT(post->body != NULL);
      264 +        }
      265 +
      266 +        return (0);
      267 +}
      268 +
 245  269  static int __do_load_post_body_fmt3(struct post *post, const struct str *input)
 246  270  {
 247  271          struct parser_output x;
 248  272          int ret;
 249  273  
 250  274          x.req            = NULL;
 251  275          x.post           = post;
 252  276          x.input          = str_cstr(input);
 253  277          x.len            = str_len(input);
 254  278          x.pos            = 0;
↓ open down ↓ 42 lines elided ↑ open up ↑
 297  321  
 298  322          str_putref(post->body); /* free the previous */
 299  323          post->body = x.stroutput;
 300  324          ASSERT(post->body);
 301  325  
 302  326          return 0;
 303  327  }
 304  328  
 305  329  static int __load_post_body(struct post *post)
 306  330  {
 307      -        static const char *exts[4] = {
      331 +        static const char *exts[5] = {
 308  332                  [2] = "html",
 309  333                  [3] = "tex",
      334 +                [4] = "md",
 310  335          };
 311  336  
 312  337          char path[FILENAME_MAX];
 313  338          struct str *raw;
 314  339          int ret;
 315  340  
 316  341          ASSERT3U(post->fmt, >=, 2);
 317      -        ASSERT3U(post->fmt, <=, 3);
      342 +        ASSERT3U(post->fmt, <=, 4);
 318  343  
 319  344          snprintf(path, FILENAME_MAX, "%s/posts/%d/post.%s",
 320  345                   str_cstr(config.data_dir), post->id, exts[post->fmt]);
 321  346  
 322  347          raw = post_get_cached_file(post, path);
 323  348          if (IS_ERR(raw))
 324  349                  return PTR_ERR(raw);
 325  350  
 326  351          switch (post->fmt) {
 327  352                  case 2:
 328  353                          ret = __do_load_post_body_fmt2(post, raw);
 329  354                          break;
 330  355                  case 3:
 331  356                          ret = __do_load_post_body_fmt3(post, raw);
 332  357                          break;
      358 +                case 4:
      359 +                        ret = __do_load_post_body_fmt4(post, raw);
      360 +                        break;
 333  361          }
 334  362  
 335  363          str_putref(raw);
 336  364  
 337  365          return ret;
 338  366  }
 339  367  
 340  368  static void __refresh_published_prop(struct post *post, struct val *lv)
 341  369  {
 342  370          /* update the time */
↓ open down ↓ 286 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX