I recently updated my hexo project, and almost everything is still ok, except that I now get an error Unexpected token '=>' while compiling ejs
from the following section.
I don't recall having this before the update, but if anything =>
should be more supported now than it was in the past?
Does ejs not support fat arrow, or is this script wrong in some other way?
<ul class="list-reset lg:flex justify-end flex-1 items-center">
<% if (page.lang == "en") { site.pages.data.filter(p => p.lang
== "en").sort( (p1, p2) => p1.menuorder - p2.menuorder
).forEach( function(p, idx) { %> <%- partial( 'menu_item',
{data: p, page: page} ) %> <% }) %> <%- partial( 'menu_item',
{data: {path:"", menutitle: "Nederlands"}} ) %> <% } else {
site.pages.data.filter(p => p.lang == "nl").sort( (p1, p2) =>
p1.menuorder - p2.menuorder ).forEach( function(p, idx) { %> <%-
partial( 'menu_item', {data: p} ) %> <% }) %> <%- partial(
'menu_item', {data: {path:"en_introduction.html", menutitle:
"English"}} ) %> <% } %>
</ul>
(vscode insists on mangling the script, but this should be easier to read)
<% if (page.lang == "en") {
site.pages.data
.filter(p => p.lang == "en")
.sort( (p1, p2) => p1.menuorder - p2.menuorder)
.forEach( function(p, idx) { %>
<%- partial( 'menu_item', {data: p, page: page} ) %>
<% }) %>
<%- partial( 'menu_item', {data: {path:"", menutitle: "Nederlands"}} ) %>
<% } else {
site.pages.data
.filter(p => p.lang == "nl")
.sort( (p1, p2) => p1.menuorder - p2.menuorder )
.forEach( function(p, idx) { %>
<%- partial( 'menu_item', {data: p} ) %>
<% }) %>
<%- partial( 'menu_item', {data: {path:"en_introduction.html", menutitle: "English"}} ) %>
<% } %>
On line 1 of your code snippet you have the opening ejs tag but are missing the closing one as you need to have an opening and closing tag on every line of ejs. I think the error from the arrow function may be due to your code editor looking for a closing tag but instead finding '=>'.
Your code:
with closing tag:
I hope this fixes the error