Leave the front-matter values that would be bigints as strings

master
Kaushal Modi 8 years ago
parent 49ac57709c
commit c504e21c62
  1. 15
      ox-hugo.el
  2. 18
      test/site/content-org/all-posts.org
  3. 20
      test/site/content/posts/front-matter-bigint-value.md

@ -2411,14 +2411,21 @@ Optional argument FORMAT can be \"toml\" or \"yaml\"."
(string= (substring val -1) "\"")) ;Last char is literally a "
(and prefer-no-quotes ;If quotes are not preferred and `val' is only alpha-numeric
(string-match-p "\\`[a-zA-Z0-9]+\\'" val))
;; or if it an integer that can be stored in the system as
;; a fixnum. For example, if `val' is
;; "10040216507682529280" that needs more than 64 bits to
;; be stored as a signed integer, it will be automatically
;; stored as a float. So (integerp (string-to-number
;; val)) will return nil.
;; https://github.com/toml-lang/toml#integer Integer
;; examples: 7, +7, -7, 7_000
(and (string-match-p "\\`[+-]?[[:digit:]_]+\\'" val)
(integerp (string-to-number val)))
(string= "true" val)
(string= "false" val)
;; or if it is a date (date, publishDate, expiryDate, lastmod)
(string-match-p org-hugo--date-time-regexp val)
;; or if it is any number (integer or float)
;; https://github.com/toml-lang/toml#integer
;; Integer examples: 7, +7, -7, 7_000
(string-match-p "\\`[+-]?[[:digit:]_]+\\'" val)
;; or if it is a float
;; https://github.com/toml-lang/toml#float
;; Float examples (decimals): 7.8, +7.8, -7.8
(string-match-p "\\`[+-]?[[:digit:]_]+\\.[[:digit:]_]+\\'" val)

@ -1774,6 +1774,24 @@ Custom TOML front-matter with TOML tables.
Custom YAML front-matter with nested maps.
#+end_description
{{{oxhugoissue(139)}}}
** Front-matter values with BigInts :bigint:toml:
:PROPERTIES:
:EXPORT_FILE_NAME: front-matter-bigint-value
:EXPORT_HUGO_CUSTOM_FRONT_MATTER: :small_int "234" :big_int "10040216507682529280"
:END:
#+begin_description
Test that front-matter values that are integers represented as
strings, but cannot be stored as 64-bit signed integers are
left as strings.
#+end_description
In this test, the small integer "234" (i.e. the one that can be
represented as a 64-bit signed integer) is saved as an integer in the
TOML front-matter.
But the big integer "10040216507682529280" which would need more than
64-bits to be stored as a signed integer is left as a string in the
TOML front-matter.
* Resources :resources:
** TOML :toml:
*** Post with resources in front-matter (TOML)

@ -0,0 +1,20 @@
+++
title = "Front-matter values with BigInts"
description = """
Test that front-matter values that are integers represented as
strings, but cannot be stored as 64-bit signed integers are
left as strings.
"""
tags = ["custom-fm", "bigint", "toml"]
draft = false
small_int = 234
big_int = "10040216507682529280"
+++
In this test, the small integer "234" (i.e. the one that can be
represented as a 64-bit signed integer) is saved as an integer in the
TOML front-matter.
But the big integer "10040216507682529280" which would need more than
64-bits to be stored as a signed integer is left as a string in the
TOML front-matter.
Loading…
Cancel
Save