From c504e21c62d58e471ed7a3f6bff5f3b4f958c5e6 Mon Sep 17 00:00:00 2001 From: Kaushal Modi Date: Tue, 5 Jun 2018 12:11:46 -0400 Subject: [PATCH] Leave the front-matter values that would be bigints as strings --- ox-hugo.el | 15 ++++++++++---- test/site/content-org/all-posts.org | 18 +++++++++++++++++ .../posts/front-matter-bigint-value.md | 20 +++++++++++++++++++ 3 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 test/site/content/posts/front-matter-bigint-value.md diff --git a/ox-hugo.el b/ox-hugo.el index 3f881e9..9817c31 100644 --- a/ox-hugo.el +++ b/ox-hugo.el @@ -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) diff --git a/test/site/content-org/all-posts.org b/test/site/content-org/all-posts.org index 242c7a6..e327be3 100644 --- a/test/site/content-org/all-posts.org +++ b/test/site/content-org/all-posts.org @@ -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) diff --git a/test/site/content/posts/front-matter-bigint-value.md b/test/site/content/posts/front-matter-bigint-value.md new file mode 100644 index 0000000..d5c17d5 --- /dev/null +++ b/test/site/content/posts/front-matter-bigint-value.md @@ -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.