diff --git a/THIRDPARTY.md b/THIRDPARTY.md index e518a42..b49ae42 100644 --- a/THIRDPARTY.md +++ b/THIRDPARTY.md @@ -31,3 +31,10 @@ Copyright: Gabriele Malaspina Designers: Gabriele Malaspina License: CC0 1.0/CC BY 4.0 CC BY 4.0 compliance: Modified to indicate the URL. Modified size. + +## Forumoji + +Affected files: everything in [`data/static/emoji`](./data/static/emoji) +URL: https://gh.vercte.net/forumoji/ +License: CC0 1.0 +Designers: lolecksdeehaha; Scratch137; 64lu (the project has many more contributors, but these are the people whose designs were reproduced here) diff --git a/data/static/emoji/angry.png b/data/static/emoji/angry.png new file mode 100644 index 0000000..7174e71 Binary files /dev/null and b/data/static/emoji/angry.png differ diff --git a/data/static/emoji/frown.png b/data/static/emoji/frown.png new file mode 100644 index 0000000..d5bba91 Binary files /dev/null and b/data/static/emoji/frown.png differ diff --git a/data/static/emoji/grin.png b/data/static/emoji/grin.png new file mode 100644 index 0000000..c31a425 Binary files /dev/null and b/data/static/emoji/grin.png differ diff --git a/data/static/emoji/imp.png b/data/static/emoji/imp.png new file mode 100644 index 0000000..e0b4f14 Binary files /dev/null and b/data/static/emoji/imp.png differ diff --git a/data/static/emoji/impangry.png b/data/static/emoji/impangry.png new file mode 100644 index 0000000..a7ed13e Binary files /dev/null and b/data/static/emoji/impangry.png differ diff --git a/data/static/emoji/neutral.png b/data/static/emoji/neutral.png new file mode 100644 index 0000000..d2e53e2 Binary files /dev/null and b/data/static/emoji/neutral.png differ diff --git a/data/static/emoji/smile.png b/data/static/emoji/smile.png new file mode 100644 index 0000000..dbb312b Binary files /dev/null and b/data/static/emoji/smile.png differ diff --git a/data/static/emoji/sob.png b/data/static/emoji/sob.png new file mode 100644 index 0000000..b56ce4e Binary files /dev/null and b/data/static/emoji/sob.png differ diff --git a/data/static/emoji/surprised.png b/data/static/emoji/surprised.png new file mode 100644 index 0000000..726cbb0 Binary files /dev/null and b/data/static/emoji/surprised.png differ diff --git a/data/static/emoji/think.png b/data/static/emoji/think.png new file mode 100644 index 0000000..2d3f235 Binary files /dev/null and b/data/static/emoji/think.png differ diff --git a/data/static/emoji/tongue.png b/data/static/emoji/tongue.png new file mode 100644 index 0000000..3b62dcc Binary files /dev/null and b/data/static/emoji/tongue.png differ diff --git a/data/static/emoji/wink.png b/data/static/emoji/wink.png new file mode 100644 index 0000000..30c6b51 Binary files /dev/null and b/data/static/emoji/wink.png differ diff --git a/lib/babycode-emoji.lua b/lib/babycode-emoji.lua new file mode 100644 index 0000000..c3e6f64 --- /dev/null +++ b/lib/babycode-emoji.lua @@ -0,0 +1,36 @@ +local emoji_template = " \"$\" " + +return { + ["angry"] = emoji_template:gsub("%$", "angry"), + + ["("] = emoji_template:gsub("%$", "frown"), + + ["D"] = emoji_template:gsub("%$", "grin"), + + ["imp"] = emoji_template:gsub("%$", "imp"), + + ["angryimp"] = emoji_template:gsub("%$", "impangry"), + ["impangry"] = emoji_template:gsub("%$", "impangry"), + + ["|"] = emoji_template:gsub("%$", "neutral"), + + [")"] = emoji_template:gsub("%$", "smile"), + + [","] = emoji_template:gsub("%$", "sob"), + ["T"] = emoji_template:gsub("%$", "sob"), + ["cry"] = emoji_template:gsub("%$", "sob"), + ["sob"] = emoji_template:gsub("%$", "sob"), + + ["o"] = emoji_template:gsub("%$", "surprised"), + ["O"] = emoji_template:gsub("%$", "surprised"), + + ["hmm"] = emoji_template:gsub("%$", "think"), + ["think"] = emoji_template:gsub("%$", "think"), + ["thinking"] = emoji_template:gsub("%$", "think"), + + ["P"] = emoji_template:gsub("%$", "tongue"), + ["p"] = emoji_template:gsub("%$", "tongue"), + + [";"] = emoji_template:gsub("%$", "wink"), + ["wink"] = emoji_template:gsub("%$", "wink"), +} diff --git a/lib/babycode.lua b/lib/babycode.lua index 7f37ddb..f0319f1 100644 --- a/lib/babycode.lua +++ b/lib/babycode.lua @@ -1,6 +1,7 @@ local babycode = {} local string_trim = require("lapis.util").trim +local emoji = require("lib.babycode-emoji") local function s_split(s, delimiter, max_matches, trim, allow_empty) local result = {} @@ -121,6 +122,14 @@ function babycode.to_html(s, escape_html) -- these can be nested, so replace open and closed separately text = text:gsub("%[(/?)quote%]", "<%1blockquote>") + + text = text:gsub(":(.-):", function(code) + if emoji[code] then + return emoji[code] + else + return code + end + end) -- replace loose links text = text:gsub("(https?://[%w-_%.%?%.:/%+=&~%@#%%]+[%w-/])", function(url) diff --git a/nginx.conf b/nginx.conf index 2b60a8c..d8d14a9 100644 --- a/nginx.conf +++ b/nginx.conf @@ -38,6 +38,11 @@ http { alias data/static/avatars; expires 1y; } + location /emoji { + alias data/static/emoji; + expires 1y; + } + location /static/js/ { alias js/; diff --git a/views/common/bbcode_help.etlua b/views/common/bbcode_help.etlua index 20dce0a..6868836 100644 --- a/views/common/bbcode_help.etlua +++ b/views/common/bbcode_help.etlua @@ -1,6 +1,25 @@
babycode guide