Skip to content
This repository has been archived by the owner on Sep 7, 2020. It is now read-only.

Commit

Permalink
Extract collection minification method so it can be used in the stati…
Browse files Browse the repository at this point in the history
…c build
  • Loading branch information
MoOx committed Nov 4, 2015
1 parent 1cff729 commit ffc4401
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
26 changes: 26 additions & 0 deletions src/md-collection-loader/__tests__/minify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import test from "tape"

import minify from "../minify"

test("statinamic/lib/md-collection-loader/minify", (t) => {
t.deepEqual(
minify([
{
head: { title: "" },
body: "whatever",
__filename: "test.t",
__url: "test",
},
]),
[
{
title: "",
__filename: "test.t",
__url: "test",
},
],
"should create a minified collection (without body)"
)

t.end()
})
7 changes: 2 additions & 5 deletions src/md-collection-loader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import filenameToUrl from "../filename-to-url"
import enhanceCollection from "../enhance-collection"
import feed from "./feed"
import cache from "./cache"
import minify from "./minify"

let timeout

Expand Down Expand Up @@ -99,11 +100,7 @@ export default function(input) {
else {
setTimeout(() => {
// we emit a collection that contains only header info + metadata
const newJSON = JSON.stringify(cache.map((item) => ({
...item.head,
__filename: item.__filename,
__url: item.__url,
})))
const newJSON = JSON.stringify(minify(cache))
// emit updated collection
this.emitFile(collectionUrl, newJSON)

Expand Down
5 changes: 5 additions & 0 deletions src/md-collection-loader/minify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default (collection) => collection.map((item) => ({
...item.head,
__filename: item.__filename,
__url: item.__url,
}))

0 comments on commit ffc4401

Please sign in to comment.