Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

porting a jekyll site to nodejs #286

Closed
UP822718 opened this issue Dec 18, 2020 · 19 comments
Closed

porting a jekyll site to nodejs #286

UP822718 opened this issue Dec 18, 2020 · 19 comments
Labels

Comments

@UP822718
Copy link

I have been trying to port a Jekyll web site for fun to nodejs. but for the life of me, I can't seem to make the website render right
This is what my attempt looks like
image
this is what it meant to look like
image
I am passing the title in as a global but it not working right.
image
just to make sure I am supposed to pass the global variable as an object?
oh and not meant to be political going to reuse and edit the theme for something else

@harttle
Copy link
Owner

harttle commented Dec 19, 2020

The front matter and page variables are provided by site generators, LiquidJS is only just a template engine. Try https://www.11ty.dev/ if you want a site generator in Node.js.

In case you want do it from scratch, the scope you passed in should be look like this:

parseAndRender(template, {
    page: { nomenu: false, fullname: 'foo', title: 'bar' }
})

And since the front matter is not supported by LiquidJS, you'll need the layout tag. Always feel free to create your first Discussion!

@UP822718
Copy link
Author

Ik and I pass all the data it needs to render the site (see code block below) and it sill not working right. I think it needs to able to pass the data from the site and page to all other layout and include but is not doing that write. i try setting it as globals and passing it into parseAndRender (individually and at the same time). What am i doing wrong?

{
  site: {
    title: 'Pirate Party UK',
    email: 'webteam@pirateparty.org.uk',
    description: 'Website for the UK Pirate Party, a centrist party focusing on Digital Rights and Freedom.',
    keywords: 'Pirate, Pirate Party, Party, PPUK, PP, United Kingdom, Politics, Digital Rights, Digital Freedom.',
    baseurl: '',
    url: 'https://www.pirateparty.org.uk',
    markdown: 'kramdown',
    gems: [ 'jekyll-paginate', 'jekyll-sitemap', 'jekyll-feed' ],
    paginate_path: '/news/:num/',
    paginate: 11,
    exclude: [
      'readme.md',
      'Gemfile',
      'Gemfile.lock',
      'package.json',
      'bower.json',
      'gulpfile.js',
      'node_modules',
      'bower_components',
      'vendor'
    ],
    sass: { style: 'compressed' },
    permalink: '/article/:title.html',
    collections: { people: [Object], policy: [Object], branches: [Object] },
    defaults: [ [Object], [Object], [Object], [Object], [Object], [Object] ],
    calendar: 'https://calendar.google.com/calendar/embed?showTitle=0&showNav=0&showDate=0&showPrint=0&showTabs=0&showCalendars=0&showTz=0&mode=AGENDA&height=500&wkst=2&hl=cs&bgcolor=%23FFFFFF&src=kddvdvu3adcjef2kro4j6mm838%40group.calendar.google.com&color=%232952A3&ctz=Europe%2FPrague',
    fb: 'https://www.facebook.com/piratepartyuk/',
    tw: 'piratepartyuk',
    'title-page': {
      big: [Object],
      'left-top': [Object],
      'right-top': [Object],
      'left-bottom': [Object],
      'right-bottom': [Object]
    },
    emptyArray: [],
    time: 1608401975682,
    pages: [],
    posts: [
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object]
    ],
    related_posts: [],
    static_files: [
      [Object], [Object], [Object], [Object], [Object], [Object],
      [Object], [Object], [Object], [Object], [Object], [Object],
      [Object], [Object], [Object], [Object], [Object], [Object],
      [Object], [Object], [Object], [Object], [Object], [Object],
      [Object], [Object], [Object], [Object], [Object], [Object],
      [Object], [Object], [Object], [Object], [Object], [Object],
      [Object], [Object], [Object], [Object], [Object], [Object],
      [Object], [Object], [Object], [Object], [Object], [Object],
      [Object], [Object], [Object], [Object], [Object], [Object],
      [Object], [Object], [Object], [Object], [Object], [Object],
      [Object], [Object], [Object], [Object], [Object], [Object],
      [Object], [Object], [Object], [Object], [Object], [Object],
      [Object], [Object], [Object], [Object], [Object], [Object],
      [Object], [Object], [Object], [Object], [Object], [Object],
      [Object], [Object], [Object], [Object], [Object], [Object],
      [Object], [Object], [Object], [Object], [Object], [Object],
      [Object], [Object], [Object], [Object],
      ... 700 more items
    ],
    html_pages: [],
    data: [
      vzkazy: [Array],
      'transparence.yml': [Array],
      'transp-uspechy': [Array],
      'top-menu.yml': [Array],
      'toc-program.yml': [Array],
      roadtrip: [Array],
      'region-map': [Object],
      freeride: []
    ],
    documents: [],
    categories: [],
    tags: [],
    api: [
      people: {},
      posts: {},
      program: {},
      'psc-kraj-l-mini': {},
      regions: {},
      search: {},
      tags: {},
      teams: {}
    ],
    paginator: NaN
  },
  content: '---\n' +
    '---\n' +
    '[\n' +
    '  {% for person in site.people %}\n' +
    '    {\n' +
    '      "uid"      : "{{ person.uid }}",\n' +
    '      "name"     : "{{ person.name | escape }}",\n' +
    '      "fullname" : "{{ person.fullname }}",\n' +
    `      "category" : "{{ person.categories | join: ' ' }}",\n` +
    `      "img"      : "{{ person.img | prepend: '/assets/img/' | relative_url }}",\n` +
    `      "mail"     : "{{ person.mail | join: ','}}",\n` +
    `      "mob"      : "{{ person.mob | join: ','}}",\n` +
    '      "description" : "{{ person.description | escape }}",\n' +
    `      "profiles" : "{{ person.mail | join: ','}}",\n` +
    '      "content"\t : "{{ person.content | strip_html | strip_newlines | remove:  "\t" | escape | remove: "\\"}}",\n' +
    '      "url"      : "{{ person.url | relative_url }}"\n' +
    '    }{% unless forloop.last %},{% endunless %}\n' +
    '  {% endfor %}\n' +
    ']\n',
  page: {
    __content: '---\n' +
      '---\n' +
      '[\n' +
      '  {% for person in site.people %}\n' +
      '    {\n' +
      '      "uid"      : "{{ person.uid }}",\n' +
      '      "name"     : "{{ person.name | escape }}",\n' +
      '      "fullname" : "{{ person.fullname }}",\n' +
      `      "category" : "{{ person.categories | join: ' ' }}",\n` +
      `      "img"      : "{{ person.img | prepend: '/assets/img/' | relative_url }}",\n` +
      `      "mail"     : "{{ person.mail | join: ','}}",\n` +
      `      "mob"      : "{{ person.mob | join: ','}}",\n` +
      '      "description" : "{{ person.description | escape }}",\n' +
      `      "profiles" : "{{ person.mail | join: ','}}",\n` +
      '      "content"\t : "{{ person.content | strip_html | strip_newlines | remove:  "\t" | escape | remove: "\\"}}",\n' +
      '      "url"      : "{{ person.url | relative_url }}"\n' +
      '    }{% unless forloop.last %},{% endunless %}\n' +
      '  {% endfor %}\n' +
      ']\n',
    content: '---\n' +
      '---\n' +
      '[\n' +
      '  {% for person in site.people %}\n' +
      '    {\n' +
      '      "uid"      : "{{ person.uid }}",\n' +
      '      "name"     : "{{ person.name | escape }}",\n' +
      '      "fullname" : "{{ person.fullname }}",\n' +
      `      "category" : "{{ person.categories | join: ' ' }}",\n` +
      `      "img"      : "{{ person.img | prepend: '/assets/img/' | relative_url }}",\n` +
      `      "mail"     : "{{ person.mail | join: ','}}",\n` +
      `      "mob"      : "{{ person.mob | join: ','}}",\n` +
      '      "description" : "{{ person.description | escape }}",\n' +
      `      "profiles" : "{{ person.mail | join: ','}}",\n` +
      '      "content"\t : "{{ person.content | strip_html | strip_newlines | remove:  "\t" | escape | remove: "\\"}}",\n' +
      '      "url"      : "{{ person.url | relative_url }}"\n' +
      '    }{% unless forloop.last %},{% endunless %}\n' +
      '  {% endfor %}\n' +
      ']\n',
    url: '/api/people.json',
    dir: '/api/people.json',
    name: '/api/people.json',
    path: '/api/people.json',
    next: null,
    previous: null
  },
  paginator: {
    paginate_path: '/blog/page:num/',
    page: 0,
    per_page: 0,
    posts: 0,
    total_posts: 0,
    total_pages: 0,
    previous_page: null,
    previous_page_path: null,
    next_page: null,
    next_page_path: null
  }
}

if need i can put the code up on github.

@UP822718
Copy link
Author

UP822718 commented Dec 19, 2020

just notes it not the same page as I pout out but there is page. title variable being passed in.

@UP822718
Copy link
Author

I will put a copy of the code up on GitHub on request. this is from the same page as

{
  site: {
    title: 'Pirate Party UK',
    email: 'webteam@pirateparty.org.uk',
    description: 'Website for the UK Pirate Party, a centrist party focusing on Digital Rights and Freedom.',
    keywords: 'Pirate, Pirate Party, Party, PPUK, PP, United Kingdom, Politics, Digital Rights, Digital Freedom.',
    baseurl: '',
    url: 'https://www.pirateparty.org.uk',
    markdown: 'kramdown',
    gems: [ 'jekyll-paginate', 'jekyll-sitemap', 'jekyll-feed' ],
    paginate_path: '/news/:num/',
    paginate: 11,
    exclude: [
      'readme.md',
      'Gemfile',
      'Gemfile.lock',
      'package.json',
      'bower.json',
      'gulpfile.js',
      'node_modules',
      'bower_components',
      'vendor'
    ],
    sass: { style: 'compressed' },
    permalink: '/article/:title.html',
    collections: { people: [Object], policy: [Object], branches: [Object] },
    defaults: [ [Object], [Object], [Object], [Object], [Object], [Object] ],
    calendar: 'https://calendar.google.com/calendar/embed?showTitle=0&showNav=0&showDate=0&showPrint=0&showTabs=0&showCalendars=0&showTz=0&mode=AGENDA&height=500&wkst=2&hl=cs&bgcolor=%23FFFFFF&src=kddvdvu3adcjef2kro4j6mm838%40group.calendar.google.com&color=%232952A3&ctz=Europe%2FPrague',
    fb: 'https://www.facebook.com/piratepartyuk/',
    tw: 'piratepartyuk',
    'title-page': {
      big: [Object],
      'left-top': [Object],
      'right-top': [Object],
      'left-bottom': [Object],
      'right-bottom': [Object]
    },
    emptyArray: [],
    time: 1608458520494,
    pages: [],
    posts: [
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object],
      [Object], [Object], [Object]
    ],
    related_posts: [],
    static_files: [
      [Object], [Object], [Object], [Object], [Object], [Object],
      [Object], [Object], [Object], [Object], [Object], [Object],
      [Object], [Object], [Object], [Object], [Object], [Object],
      [Object], [Object], [Object], [Object], [Object], [Object],
      [Object], [Object], [Object], [Object], [Object], [Object],
      [Object], [Object], [Object], [Object], [Object], [Object],
      [Object], [Object], [Object], [Object], [Object], [Object],
      [Object], [Object], [Object], [Object], [Object], [Object],
      [Object], [Object], [Object], [Object], [Object], [Object],
      [Object], [Object], [Object], [Object], [Object], [Object],
      [Object], [Object], [Object], [Object], [Object], [Object],
      [Object], [Object], [Object], [Object], [Object], [Object],
      [Object], [Object], [Object], [Object], [Object], [Object],
      [Object], [Object], [Object], [Object], [Object], [Object],
      [Object], [Object], [Object], [Object], [Object], [Object],
      [Object], [Object], [Object], [Object], [Object], [Object],
      [Object], [Object], [Object], [Object],
      ... 700 more items
    ],
    html_pages: [],
    data: [
      vzkazy: [Array],
      transparence: [Array],
      'transp-uspechy': [Array],
      'top-menu': [Array],
      'toc-program': [Array],
      roadtrip: [Array],
      'region-map': [Object],
      freeride: []
    ],
    documents: [],
    categories: [],
    tags: [],
    api: [
      people: {},
      posts: {},
      program: {},
      'psc-kraj-l-mini': {},
      regions: {},
      search: {},
      tags: {},
      teams: {}
    ],
    paginator: NaN
  },
  content: '<p>This is the home page for the Materials section of the website.\n' +
    "This should include a Markdown Page of 'Design Style etc.' (which will need to be re-written to match the website)\n" +
    'This should also include links to a new folder assets/materials/ which will host all the previous campaign / election materials</p>\n',
  page: {
    title: 'Materials',
    layout: 'page',
    rbar: 'people, tw',
    __content: '\n' +
      '\n' +
      '\n' +
      'This is the home page for the Materials section of the website.\n' +
      "This should include a Markdown Page of 'Design Style etc.' (which will need to be re-written to match the website)\n" +
      'This should also include links to a new folder assets/materials/ which will host all the previous campaign / election materials\n',
    content: '\n' +
      '\n' +
      '\n' +
      'This is the home page for the Materials section of the website.\n' +
      "This should include a Markdown Page of 'Design Style etc.' (which will need to be re-written to match the website)\n" +
      'This should also include links to a new folder assets/materials/ which will host all the previous campaign / election materials\n',
    url: '/materials/index.md',
    dir: '/materials/index.md',
    name: '/materials/index.md',
    path: '/materials/index.md',
    next: null,
    nomenu: true,
    previous: null
  },
  paginator: {
    paginate_path: '/blog/page:num/',
    page: 0,
    per_page: 0,
    posts: 0,
    total_posts: 0,
    total_pages: 0,
    previous_page: null,
    previous_page_path: null,
    next_page: null,
    next_page_path: null
  }
}
 

I think there is a difference in how Jekyll liquid to pass variables and how liquids pass variables. I already did have to make some mods to the liquid files changing {{content}} to {% block %}{% endblock %} so other differents mite be a thing???? are these difference bugs?

@harttle
Copy link
Owner

harttle commented Dec 20, 2020

mods to the liquid files changing {{content}} to {% block %}{% endblock %}

As I said , LiquidJS is a template engine, the content variable is supposed to be passed in by a site generator.

i try setting it as globals and passing it into parseAndRender

Did you try the globals option, like const engine = new Liquid({globals: {page: blabla}})

@UP822718
Copy link
Author

that how is it rn with the
const engine = new Liquid({globals: {page: blabla}})
I also tryed
const engine = new Liquid({"globals": {page: blabla}}) but that does not work.
also engine.parseAndRenderSync(html_,{page: blabla}); dose not work.
nor a combination of them both

@UP822718
Copy link
Author

also i am passing in the variable {{content}} as unparsed liquid. should it be passed to work?

@harttle
Copy link
Owner

harttle commented Dec 20, 2020

content should be a parsed and rendered HTML string.

@UP822718
Copy link
Author

I will try that
Thx @harttle you're awesome
ok, any idea about why I can't get globals to work right?

@harttle
Copy link
Owner

harttle commented Dec 20, 2020

any idea about why I can't get globals to work right?

No idea. It helps if you can provide a minimal demo or a jsFiddle link.

@UP822718
Copy link
Author

UP822718 commented Dec 20, 2020

this is the code i am working on (some of the code strip out). It sill a WIP it not a very minimal demo or jsFiddle.
https://github.com/UP822718/jally-but-JavaScript

The real website to compare the address is https://pirateparty.org.uk/materials/
as I Is a WIP path are not working correctly yet you will find it at http://localhost:3001/materials/index.md
There are a lot of over things not working but one thing at a time so plz don't report them hare.
sorry for the sate of my code

@UP822718
Copy link
Author

I have been working on this thing for two weeks, and I am stuck as heck with something that should be so simple—globals used as a global variable. I can't find where I am going wrong, and the data I am passing in seem to be right.

I am thing about porting to a different templating engine to the to come over this perceived bug this project (it could be sill in my code), but I would really do want to keep in liquids-js 😞. If I give up on using this library in my code, I want to say I really like the idea of this project and if the bug is in your code, I hope u find it and fix it soon.

harttle added a commit that referenced this issue Dec 22, 2020
harttle added a commit that referenced this issue Dec 22, 2020
@harttle
Copy link
Owner

harttle commented Dec 22, 2020

Sadly I have no bandwidth to debug into you repo, but I managed to update the demo/nodejs/ to demonstrate a working usage for globals used in templates imported by layout and render (this one is also nested).

The global data title is accessible in both html.liquid and footer.liquid. To run the demo:

  1. cd demo/nodejs
  2. npm i
  3. npm start

You'll see output like:

> liquidjs-demo-nodejs@ start /mnt/e/GitHub/liquidjs/demo/nodejs
> node index.js

<html>
  <head><meta name="title" content="LiquidJS Demo"></head>
  <body>

<h1>LiquidJS Demo</h1>
<ul>

  <li>1 - fork and clone</li>

  <li>2 - make it better</li>

  <li>3 - make a pull request</li>

</ul>
    <small>LiquidJS Demo</small>
  </body>
</html>

@pdehaan
Copy link
Contributor

pdehaan commented Dec 22, 2020

Here's a mediocre example of rendering a Markdown file with global and local variables (from the Markdown file's front matter):

const matter = require("gray-matter");
const { Liquid } = require("liquidjs");
const marked = require("marked");

const pkg = require("./package.json");

main();

async function main() {
  const globals = {
    name: "alice",
    age: 45,
    homepage: "https://bing.com/",
    // Make values from package.json available globally.
    pkg
  };
  const engine = new Liquid({ globals });
  await renderFile("./docs.md", engine);
}

async function renderFile(file, engine = new Liquid()) {
  const { content, data: locals } = matter.read(file);
  const md = await engine.parseAndRender(content.trim(), locals);
  const html = marked(md);
  console.log(html);
}

Where my "./docs.md" file looks like this:

---
# Local variables
title: This is a title
---

<!-- {{ pkg.name }}@{{ pkg.version }} -->

# {{ title }}

And a paragraph.  
And another one.

A second paragraph.

[links]({{ homepage }})

&mdash; By {{ name | capitalize }}

You'd still need to add a bit of code to convert the markdown into HTML (using markdown-it or something else), but that might get you started.

But to echo @harttle's comments above, probably better just to use 11ty (which supports Liquid templates by default) and let 11ty worry about processing source folders and output folders and all the other plumbing needed for a static blog.

@UP822718
Copy link
Author

UP822718 commented Dec 23, 2020

After a look at 11ty, I don't think to meet my other needs.

what I think I cant do form reading online with 11ty or with plugins for 11ty

  • there is no HTTP/2 (SPDY) (or HTTP/3 (aka QUIC) [far future plans]) support in that Project and no way I can find to add it.

    • HTTP/2 or 3 push
    • web push (not relly need but work better with HTTP/2 or 3)
  • I cant see a way of an add SPARQL endpoint

  • comments (and social)

    • Activity Streams
      • activity pub?????
  • SPARQL endpoint

    • SemanticSitemap
  • on the fly subresource Integrity (SRI) inclusion

  • IPFS

  • passport login

  • RDF feed

  • payment and donate

    • Basic Attention Token
  • p2p Beaker

  • WebTorrent
    I might able to do with 11ty

  • flow/bock programming use to update website content inclusion

    • data retrieval from data sources
      • JSON
      • RDF
      • SQL
      • HTML
      • XML
      • SPARQL
      • GraphQL
    • data processing and cleaning
    • dynamically updating web pages based on new data
    • dynamic creation of pages

what 11ty can do (with or without plugins)

  • liquid passing
    • keep this website theme i like and want to use form something else
  • markdown passing
    • markdown-it plugins
  • CDN
  • Push notification
  • RSS/RDF/ATOM
  • payment and donate
  • maybe paypal donate
    so rolling my own seems to be the best way to go and a tempaling engine like liquidjs being part of that

@UP822718
Copy link
Author

UP822718 commented Dec 23, 2020

@pdehaan you had a look at my code form what you have seen is it a bug in my code, the template itself, liquid-js code or hesitate to comment/Don't know.
many thank for your time and work on this project awesome.

@pdehaan
Copy link
Contributor

pdehaan commented Dec 23, 2020

@UP822718 I haven't really had a chance to look through the code in the repo or above because, well, it's a lot of code.

But based on the docs and my simple test case above, I don't think it'd be a bug in liquidjs since I can get globals and local variables to render in a template.

As for the 11ty questions above, yeah, 11ty is just a static site generator, so most of the HTTP2/3 and server stuff is out of scope. You'd either need to wrap the generated static files in an Express server, or some other solution (like building everything in Next.js+React, or doing a lot of the work with client side JavaScript).

@UP822718
Copy link
Author

UP822718 commented Dec 23, 2020

ok, thx @pdehaan I will have a look at Next.js+React. @harttle. just noticed there was two message way back right next to each other and I did not notice at the time and skipped one. my bad. i think I will be able to do it now maybe
as you can see it working progress
image
thx both of you for being awesome and putting up with me.
have a happy Xmas, Saturnalia or whatever you celebrate
also, open collective or Patreon?

@UP822718
Copy link
Author

Ok ok......
I think it a bug in liquids-js
i can get the title if I use { render 'xyz.html' } in replacement to { layout 'xyz.html' } in the layout and includes
but not when I am using layout when adding layout and includes
to test change line 42 (inside the fs.readFileSync function) of midware/liquid/liquid.js
data["__content"] = `{% render \'${data.layout}.html\' %}\n` + data["__content"];
or
data["__content"] = `{% layout \'${data.layout}.html\' %}\n` + data["__content"];

@harttle harttle closed this as completed Jan 23, 2021
Repository owner locked and limited conversation to collaborators Jan 23, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
Projects
None yet
Development

No branches or pull requests

3 participants