Skip to content

Commit

Permalink
update Merge to prevent infinite loops
Browse files Browse the repository at this point in the history
  • Loading branch information
levinunnink committed Jun 24, 2023
1 parent ede8b06 commit bb683ab
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 0 deletions.
7 changes: 7 additions & 0 deletions examples/compile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const CompileDirectoryCommand = require('../lib/commands/CompileDirectoryCommand');

const command = new CompileDirectoryCommand();

command.handle(`${__dirname}`, {
destinationPath: `${__dirname}/../build`
});
37 changes: 37 additions & 0 deletions examples/html/about/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!DOCTYPE html><html lang="en"><head>
<meta charset="utf-8">
<title>Site coming soon</title>
<meta name="description" content="Something awesome is coming to this URL soon.">
<meta name="author" content="Levi Nunnink">
<link rel="stylesheet" href="/style.css" />
<script data-type="merge-script">
window.mergeState = {
name: 'Fun Times',
items: [
{link: 'https://nunn.ink', label: 'Personal Site'},
{link: 'https://twitter.com/LeviNunnink', label: 'Twitter'},
{link: 'https://github.com/LeviNunnink', label: 'Github'}
],
type: 'boom',
test: 'test',
};
</script>

<body>
<div class="container">
<div class="inside">
<h2>Hello, <span data-merge-content="name">...</span></h2>
<p>You can start publishing here any
time you want. Just open your local folder, make some changes, and hit publish.</p>
<p>Feel free to use this page as a starter template.</p>
<ul class="links" data-merge-repeat="items">
<li>
<a href="${link}">${label}</a>
</li>
</ul>
</div>
<div data-merge-if="type" data-merge-equals="boom">BOOM</div>
<div data-merge-include="/footer.html"></div>
</div>
</body>
</html>
18 changes: 18 additions & 0 deletions examples/html/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "Jim",
"items": [{
"link": "https://nunn.ink",
"label": "Personal Site"
},
{
"link": "https://twitter.com/LeviNunnink",
"label": "Twitter"
},
{
"link": "https://github.com/LeviNunnink",
"label": "Github"
}
],
"type": "boom",
"test": "test"
}
5 changes: 5 additions & 0 deletions examples/html/footer.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<footer>
<a href="https://wunderbucket.io" title="Static hosting for designers &amp; developers.">
Footer Test
</a>
</footer>
30 changes: 30 additions & 0 deletions examples/html/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html><html lang="en"><head>
<meta charset="utf-8">
<title>Site coming soon</title>
<meta name="description" content="Something awesome is coming to this URL soon.">
<meta name="author" content="Levi Nunnink">
<link rel="stylesheet" href="/style.css" />
<body>
<div class="container">
<div class="inside">
<h2>Hello, <span data-merge-content="name">...</span></h2>
<p>You can start publishing here any
time you want. Just open your local folder, make some changes, and hit publish.</p>
<p>Feel free to use this page as a starter template.</p>
<a href="/about/">ABOUT</a>
<ul class="links" data-merge-repeat="items">
<li>
<a href="${link}">${label}</a>
</li>
</ul>
</div>
<div data-merge-if="type" data-merge-equals="boom">BOOM</div>
<h2>Markdown Content:</h2>
<div data-merge-include-markdown="test.md"></div>
<div data-merge-include="footer.html"></div>
</div>
<script data-type="merge-script">
merge.loadState('/data.json');
</script>
</body>
</html>
3 changes: 3 additions & 0 deletions examples/html/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
font-family: 'Courier New', Courier, monospace;
}
36 changes: 36 additions & 0 deletions examples/html/test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Marked - Markdown Parser
========================

[Marked] lets you convert [Markdown] into HTML. Markdown is a simple text format whose goal is to be very easy to read and write, even when not converted to HTML. This demo page will let you type anything you like and see how it gets converted. Live. No more waiting around.

How To Use The Demo
-------------------

1. Type in stuff on the left.
2. See the live updates on the right.

That's it. Pretty simple. There's also a drop-down option in the upper right to switch between various views:

- **Preview:** A live display of the generated HTML as it would render in a browser.
- **HTML Source:** The generated HTML before your browser makes it pretty.
- **Lexer Data:** What [marked] uses internally, in case you like gory stuff like this.
- **Quick Reference:** A brief run-down of how to format things using markdown.

Why Markdown?
-------------

It's easy. It's not overly bloated, unlike HTML. Also, as the creator of [markdown] says,

> The overriding design goal for Markdown's
> formatting syntax is to make it as readable
> as possible. The idea is that a
> Markdown-formatted document should be
> publishable as-is, as plain text, without
> looking like it's been marked up with tags
> or formatting instructions.
Ready to start writing? Either start changing stuff on the left or
[clear everything](/demo/?text=) with a simple click.

[Marked]: https://github.com/markedjs/marked/
[Markdown]: http://daringfireball.net/projects/markdown/
16 changes: 16 additions & 0 deletions examples/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const getPort = require('get-port');
const openUrl = require('openurl');

const Server = require('../lib/server/Server');

const run = async () => {
const root = "/Users/lnunnink/Projects/merge/test";
const port = await getPort();

const server = new Server(port, root);
server.start();

openUrl.open(`http://localhost:${port}`);
};

run();
4 changes: 4 additions & 0 deletions lib/Merge.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ class Merge {
* path.
*/
async loadState(urlOrObject) {
if (this.state) {
// State has already been loaded
return;
}
if (typeof urlOrObject === 'object') {
this.state = urlOrObject;
if (this.document) this.parse();
Expand Down

0 comments on commit bb683ab

Please sign in to comment.