Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mampf-menu-fetcher
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
RZ utils
mampf-menu-fetcher
Commits
911383d3
Commit
911383d3
authored
5 years ago
by
Raven Z.
Browse files
Options
Downloads
Patches
Plain Diff
some clean up and formatting
parent
4eef9954
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
.gitignore
+1
-0
1 addition, 0 deletions
.gitignore
format.js
+38
-0
38 additions, 0 deletions
format.js
mail.mustache
+21
-0
21 additions, 0 deletions
mail.mustache
main.js
+34
-7
34 additions, 7 deletions
main.js
with
94 additions
and
7 deletions
.gitignore
0 → 100644
+
1
−
0
View file @
911383d3
/node_modules
This diff is collapsed.
Click to expand it.
format.js
0 → 100644
+
38
−
0
View file @
911383d3
'
use strict
'
;
const
fs
=
require
(
'
fs
'
)
const
path
=
require
(
'
path
'
)
const
mustache
=
require
(
'
mustache
'
)
const
moment
=
require
(
'
moment
'
)
const
dataText
=
fs
.
readFileSync
(
path
.
join
(
__dirname
,
'
menu.json
'
),
'
utf-8
'
)
const
tplText
=
fs
.
readFileSync
(
path
.
join
(
__dirname
,
'
mail.mustache
'
),
'
utf-8
'
)
//console.log('tpl: ', tplText)
//console.log('data:', dataText)
const
data
=
JSON
.
parse
(
dataText
)
const
dayData
=
data
.
days
[
moment
().
format
(
'
YYYY-MM-DD
'
)]
const
usedAdditives
=
{}
dayData
.
menu
.
forEach
(
m
=>
m
.
description
.
forEach
(
d
=>
(
d
.
notes
||
[]).
forEach
(
n
=>
usedAdditives
[
n
]
=
true
)
)
)
dayData
.
extras
.
forEach
(
e
=>
e
.
options
.
forEach
(
o
=>
(
o
.
description
.
notes
||
[]).
forEach
(
n
=>
usedAdditives
[
n
]
=
true
)
)
)
const
view
=
{
today
:
dayData
,
url
:
data
.
url
,
fetchedAt
:
data
.
fetchedAt
,
additives
:
Object
.
keys
(
data
.
additives
)
.
filter
(
k
=>
usedAdditives
[
k
])
.
map
(
k
=>
({
symbol
:
k
,
text
:
data
.
additives
[
k
]
}))
}
const
rendered
=
mustache
.
render
(
tplText
,
view
)
console
.
log
(
rendered
)
This diff is collapsed.
Click to expand it.
mail.mustache
0 → 100644
+
21
−
0
View file @
911383d3
~ Menu for
{{
today
.
date
}}
~
{{#
today
.
menu
}}
{{
category
}}
(
{{
price
}}
)
{{#
labels
}}
[
{{
.
}}
]
{{/
labels
}}
:
{{#
description
}}
-
{{
text
}}
{{#
notes
}}
[
{{
.
}}
]
{{/
notes
}}
{{/
description
}}
{{/
today
.
menu
}}
{{#
today
.
extras
}}
{{
category
}}
:
{{#
options
}}
-
{{#
description
}}
{{
text
}}
{{#
notes
}}
[
{{
.
}}
]
{{/
notes
}}{{/
description
}}
{{/
options
}}
{{/
today
.
extras
}}
Additives:
{{#
additives
}}
[
{{
symbol
}}
]:
{{
text
}}
{{/
additives
}}
This diff is collapsed.
Click to expand it.
main.js
+
34
−
7
View file @
911383d3
...
@@ -45,7 +45,7 @@ function parseDay(dayDom) {
...
@@ -45,7 +45,7 @@ function parseDay(dayDom) {
return
{
return
{
date
:
date
.
format
(
'
YYYY-MM-DD
'
),
date
:
date
.
format
(
'
YYYY-MM-DD
'
),
label
:
titleText
,
label
:
titleText
,
today
:
isActive
,
//
today: isActive,
menu
:
[...
menues
],
menu
:
[...
menues
],
extras
,
extras
,
}
}
...
@@ -60,6 +60,7 @@ function parseMenuEntry(row) {
...
@@ -60,6 +60,7 @@ function parseMenuEntry(row) {
case
'
Rind
'
:
return
'
beef
'
case
'
Rind
'
:
return
'
beef
'
case
'
Geflügel
'
:
return
'
poultry
'
case
'
Geflügel
'
:
return
'
poultry
'
case
'
Fisch
'
:
return
'
fish
'
case
'
Fisch
'
:
return
'
fish
'
case
'
Lamm
'
:
return
'
lamb
'
case
'
odd
'
:
return
null
case
'
odd
'
:
return
null
case
'
even
'
:
return
null
case
'
even
'
:
return
null
case
'
bg-color
'
:
return
null
case
'
bg-color
'
:
return
null
...
@@ -75,6 +76,11 @@ function parseMenuEntry(row) {
...
@@ -75,6 +76,11 @@ function parseMenuEntry(row) {
const
description
=
parseDescription
(
descDom
)
const
description
=
parseDescription
(
descDom
)
const
nutrition
=
parseNutrition
(
nutrDom
)
const
nutrition
=
parseNutrition
(
nutrDom
)
description
.
forEach
(
d
=>
{
if
(
d
.
notes
)
d
.
notes
=
d
.
notes
.
filter
(
n
=>
!
labels
.
includes
(
n
))
})
return
{
return
{
labels
,
labels
,
category
,
category
,
...
@@ -112,15 +118,36 @@ function parseDescription(descDom) {
...
@@ -112,15 +118,36 @@ function parseDescription(descDom) {
const
parts
=
[]
const
parts
=
[]
descDom
.
childNodes
.
forEach
(
node
=>
{
descDom
.
childNodes
.
forEach
(
node
=>
{
if
(
node
.
nodeName
!==
'
#text
'
)
return
;
if
(
node
.
nodeName
!==
'
#text
'
)
return
;
if
(
node
.
textContent
.
trim
()
===
''
)
return
;
const
textRaw
=
node
.
data
.
replace
(
/^
\s
*
(\|\s
*
)
|
\s
*$/g
,
''
)
const
textParts
=
textRaw
.
split
(
'
|
'
).
map
(
s
=>
s
.
trim
())
if
(
textParts
.
length
>
1
)
{
textParts
.
slice
(
0
,
-
1
)
.
map
(
t
=>
({
text
:
t
}))
.
forEach
(
p
=>
parts
.
push
(
p
))
}
let
part
=
{
let
part
=
{
text
:
node
.
data
.
replace
(
/^
\s
*
(\|\s
*
)
|
\s
*$/g
,
''
)
text
:
textParts
[
textParts
.
length
-
1
]
}
}
let
nextNode
=
node
.
nextSibling
let
nextNode
=
node
.
nextSibling
if
(
nextNode
&&
nextNode
.
nodeName
===
'
SUP
'
)
{
while
(
nextNode
)
{
part
.
notes
=
(
nextNode
.
textContent
||
'
?
'
)
if
(
nextNode
.
nodeName
===
'
SUP
'
)
{
const
oldNotes
=
part
.
notes
||
[]
const
newNotes
=
(
nextNode
.
textContent
||
'
?
'
)
.
split
(
'
,
'
)
.
split
(
'
,
'
)
.
map
(
s
=>
s
.
trim
())
.
map
(
s
=>
s
.
trim
())
part
.
notes
=
[...
oldNotes
,
...
newNotes
]
nextNode
=
nextNode
.
nextSibling
continue
}
else
if
(
nextNode
.
nodeName
===
'
#text
'
&&
nextNode
.
textContent
.
trim
()
===
''
)
{
nextNode
=
nextNode
.
nextSibling
continue
}
break
}
}
parts
.
push
(
part
)
parts
.
push
(
part
)
})
})
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment