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

Commit

Permalink
Removed: phenomicLoaderPlugins & phenomicLoaderPresets from "…
Browse files Browse the repository at this point in the history
…phenomic"

To avoid shipping unnecessary code into the client bundle (regression
from 0.16.0), we removed plugins & presets from “phenomic” import.
Please directly use ``require(“phenomic/lib/loader-*``, by replacing
camelCase by dashedCase.

- ``phenomicLoaderPlugins.initBodyPropertyFromContent``
->
``require("./phenomic-loader-plugin-init-body-property-from-content").de
fault``,
- ``phenomicLoaderPlugins.initHeadPropertyFromConfig``
->
``require("./phenomic-loader-plugin-init-head-property-from-config").def
ault``,
- ``phenomicLoaderPlugins.initHeadPropertyFromContent``
->
``require("./phenomic-loader-plugin-init-head-property-from-content").de
fault``,
- ``phenomicLoaderPlugins.initRawPropertyFromContent``
->
``require("./phenomic-loader-plugin-init-raw-property-from-content").def
ault``,
- ``phenomicLoaderPlugins.initRawBodyPropertyFromContent``
->
``require("./phenomic-loader-plugin-init-rawBody-property-from-content")
.default``,
-
``phenomicLoaderPlugins.markdownInitHeadDescriptionPropertyFromContent``
->
``require("./phenomic-loader-plugin-markdown-init-head.description-prope
rty-from-content").default``,
- ``phenomicLoaderPlugins.markdownTransformBodyPropertyToHtml``
->
``require("./phenomic-loader-plugin-markdown-transform-body-property-to-
html").default``,
- ``phenomicLoaderPresets.default``
-> ``require("./phenomic-loader-preset-default").default``,
- ``phenomicLoaderPresets.markdown``
-> ``require("./phenomic-loader-preset-markdown").default``,
  • Loading branch information
MoOx committed Sep 10, 2016
1 parent 89abc71 commit 08bd04f
Show file tree
Hide file tree
Showing 43 changed files with 60 additions and 95 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ coverage
lib

# some tests output some files
src/phenomic-loader/__tests__/output/
src/loader/__tests__/output/

# tests results
**/__tests__/_output*
Expand Down
20 changes: 10 additions & 10 deletions docs/content/docs/usage/configuration/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ is crucial (in the phenomic-theme-base, it's the first loader) :

- it allows you to control what text engine to use
(default to Markdown using [remark](http://remark.js.org/)
using a solid [default](https://github.com/MoOx/phenomic/blob/master/src/phenomic-loader-plugin-markdown-transform-body-property-to-html/index.js))
using a solid [default](https://github.com/MoOx/phenomic/blob/master/src/loader-plugin-markdown-transform-body-property-to-html/index.js))
and will generate JSON files, that will be consumed for the front-end,
- it handles the generation of the collection data,
- it allows you to generate some RSS feeds.
Expand All @@ -39,7 +39,7 @@ Here is a commented part of a webpack configuration that use all options
//...

import pkg from "./package.json"
import { phenomicLoader, phenomicLoaderPlugins } from "phenomic"
import { phenomicLoader } from "phenomic"

export const makeConfig = (config = {}) => {
return {
Expand Down Expand Up @@ -67,25 +67,25 @@ export const makeConfig = (config = {}) => {
// below are the default values,
// you don't need those by default
plugins: [
phenomicLoaderPlugins.initHeadPropertyFromConfig,
phenomicLoaderPlugins.initHeadPropertyFromContent,
phenomicLoaderPlugins.initBodyPropertyFromContent,
phenomicLoaderPlugins.markdownInitHeadDescriptionPropertyFromContent,
phenomicLoaderPlugins.markdownTransformBodyPropertyToHtml,
require("phenomic/lib/loader-plugin-init-head-property-from-config").default,
require("phenomic/lib/loader-plugin-init-head-property-from-content").default,
require("phenomic/lib/loader-plugin-init-body-property-from-content").default,
require("phenomic/lib/loader-plugin-markdown-init-head.description-property-from-content").default,
require("phenomic/lib/loader-plugin-markdown-transform-body-property-to-html").default,
// here you can add/replace any function you want
// for examples, see
// https://github.com/MoOx/phenomic/blob/master/src/
// eg: if you need the raw file content in your pages,
// you can add the following plugin that will add a `raw` property
// phenomicLoaderPlugins.addRawProperty,
// require("phenomic/lib/loader-plugin-init-raw-property-from-content").default,
// if you want raw body (text content without the front-matter)
// you can add the following plugin that will add a `rawBody` property
// phenomicLoaderPlugins.addRawBodyProperty,
// require("phenomic/lib/loader-plugin-init-rawBody-property-from-content").default,
]

// default values for `head`
// this value can be defined and used by the plugin
// initHeadPropertyFromConfig
// "phenomic/lib/loader-plugin-init-head-property-from-config"
defaultHead: {
layout: "Post",
comments: true,
Expand Down
84 changes: 33 additions & 51 deletions docs/content/docs/usage/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,60 +36,45 @@ See the last section to know how to write a plugin (spoiler: it's easy).

## Existing Plugins

For now, plugins are accessible in ``phenomicLoaderPlugins`` in ``phenomic``.
For now, plugins are accessible in ``phenomic/lib/loader-plugin-*``.

```js
import { phenomicLoaderPlugins } from "phenomic"

phenomicLoaderPlugins.[camelCasedNameOfThePlugin]
// eg: phenomic-loader-plugin-init-body-property-from-content
// will be accessible under
// phenomicLoaderPlugins.initBodyPropertyFromContent
import initHeadPropertyFromConfig from "phenomic/lib/loader-plugin-init-head-property-from-config"
```

*This might change if phenomic is split into multiple packages.*
See [#598](https://github.com/MoOx/phenomic/issues/598) for more informations.

### ``phenomic-loader-plugin-init-body-property-from-content``
### ``phenomic/lib/loader-plugin-init-body-property-from-content``

This plugin initializes the ``body`` property from data retrieved in the file.
It takes the content of the input that is below the front-matter.

*For now accessible via ``phenomicLoaderPlugins.initBodyPropertyFromContent``.*

### ``phenomic-loader-plugin-init-head-property-from-config``
### ``phenomic/lib/loader-plugin-init-head-property-from-config``

This plugin initializes in the ``head`` property from ``defaultConfig`` in the
webpack ``phenomic`` configuration section.
It won't override existing key/values in the ``head`` if there is any.

*For now accessible via ``phenomicLoaderPlugins.initHeadPropertyFromConfig``.*

### ``phenomic-loader-plugin-init-head-property-from-content``
### ``phenomic/lib/loader-plugin-init-head-property-from-content``

This plugin initializes in the ``head`` property from data retrieved in the file.
It takes the front-matter of the input and map it as key => value.

*For now accessible via ``phenomicLoaderPlugins.initHeadPropertyFromContent``.*

### ``phenomic-loader-plugin-init-raw-property-from-content``
### ``phenomic/lib/loader-plugin-init-raw-property-from-content``

This plugin initializes in a ``raw`` property.
This property contains the entire file as raw data.
Useful if you front-end need to handle the content of the file.

*For now accessible via ``phenomicLoaderPlugins.initRawPropertyFromContent``.*

### ``phenomic-loader-plugin-init-rawBody-property-from-content``
### ``phenomic/lib/loader-plugin-init-rawBody-property-from-content``

This plugin initializes in a ``rawBody`` property.
This property contains the content of the file that is below the front-matter,
as raw data.
Useful if you front-end need to handle the content of the file.

*For now accessible via ``phenomicLoaderPlugins.initRawBodyPropertyFromContent``.*

### ``phenomic-loader-plugin-markdown-init-head.description-property-from-content``
### ``phenomic/lib/loader-plugin-markdown-init-head.description-property-from-content``

This plugin initializes a ``description`` property in the ``head``, based on the
content accessible below the front-matter.
Expand All @@ -105,16 +90,12 @@ You can pass options to ``phenomic`` section in webpack configuration.
}
```

*For now accessible via ``phenomicLoaderPlugins.markdownInitHeadDescriptionPropertyFromContent``.*

### ``phenomic-loader-plugin-markdown-transform-body-property-to-html``
### ``phenomic/lib/loader-plugin-markdown-transform-body-property-to-html``

This plugin will transform the ``body`` property into html.
This plugin will assumes your content is markdown and will use
[``remark``](http://remark.js.org/) with
[some plugins](https://github.com/MoOx/phenomic/blob/master/src/phenomic-loader-plugin-markdown-transform-body-property-to-html/index.js) for the transformation.

*For now accessible via ``phenomicLoaderPlugins.markdownTransformBodyPropertyToHtml``.*
[some plugins](https://github.com/MoOx/phenomic/blob/master/src/phenomic/lib/loader-plugin-markdown-transform-body-property-to-html/index.js) for the transformation.


## Presets
Expand All @@ -140,21 +121,21 @@ notation is more verbose, especially if you have multiple plugins.

Phenomic provides the following presets:

### ``phenomic-loader-preset-default``
### ``phenomic/lib/loader-preset-default``

- ``phenomic-loader-plugin-init-head-property-from-config``
- ``phenomic-loader-plugin-init-head-property-from-content``
- ``phenomic-loader-plugin-init-body-property-from-content``
- ``phenomic/lib/loader-plugin-init-head-property-from-config``
- ``phenomic/lib/loader-plugin-init-head-property-from-content``
- ``phenomic/lib/loader-plugin-init-body-property-from-content``

🛠 This preset is kind of the phenomic default requirement.
Use it if you want to use classic files with a front-matter and any text format.
**Feel free to take a look to markdown preset to implement your own engine!**

### ``phenomic-loader-preset-markdown``
### ``phenomic/lib/loader-preset-markdown``

- ``phenomic-loader-preset-default``
- ``phenomic-loader-plugin-markdown-init-head.description-property-from-content``
- ``phenomic-loader-plugin-markdown-transform-body-property-to-html``
- ``phenomic/lib/loader-preset-default``
- ``phenomic/lib/loader-plugin-markdown-init-head.description-property-from-content``
- ``phenomic/lib/loader-plugin-markdown-transform-body-property-to-html``

❤️ This preset is the one used by default in Phenomic. It allows you to consume
common markdown files that have a front-matter out of the box.
Expand All @@ -167,9 +148,7 @@ You can use some plugins, but not the one that will transform the markdown as
HTML.

```js
import { phenomicLoader, phenomicLoaderPresets } from "phenomic"
// or if you want to use some each plugins manually
// import { phenomicLoader, phenomicLoaderPlugins } from "phenomic"
import { phenomicLoader } from "phenomic"

// ...

Expand All @@ -183,18 +162,18 @@ import { phenomicLoader, phenomicLoaderPresets } from "phenomic"

plugins: [
// here are the unopininated default plugins
...phenomicLoaderPresets.default,
...require("phenomic/lib/loader-preset-default").default,

// Instead of specifing via the preset, you can cherry pick some,
// phenomicLoaderPlugins.initHeadPropertyFromConfig,
// phenomicLoaderPlugins.initHeadPropertyFromContent,
// phenomicLoaderPlugins.initBodyPropertyFromContent,
// require("phenomic/lib/loader-plugin-init-head-property-from-config").default,
// require("phenomic/lib/loader-plugin-init-head-property-from-content").default,
// require("phenomic/lib/loader-plugin-init-body-property-from-content").default,

// ...phenomicLoaderPresets.markdown
// ...require("phenomic/lib/loader-preset-markdown").default
// The commented preset above is part of the default renderer.
// You can also cherry pick on plugin or the other
// phenomicLoaderPlugins.markdownInitHeadDescriptionPropertyFromContent,
// phenomicLoaderPlugins.transformMdBodyPropertyToHtml,
// require("phenomic/lib/loader-plugin-markdown-init-head.description-property-from-content").default,
// require("phenomic/lib/loader-plugin-transform-md-body-property-to-html").default,

// here is an example of another transformation
({ result }) => {
Expand All @@ -210,10 +189,13 @@ import { phenomicLoader, phenomicLoaderPresets } from "phenomic"
// https://github.com/MoOx/phenomic/blob/master/src/
}
}
]
},
},
...
],
},
},

// ...
]
}
```

## Writing plugins
Expand Down
2 changes: 1 addition & 1 deletion docs/webpack.config.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export const makeConfig = (config = {}) => {

phenomic: {
context: path.join(__dirname, config.source),
// plugins: [ ...phenomicLoaderPresets.markdown ]
// plugins: [ ...require("phenomic/lib/loader-preset-markdown").default ]
// see https://phenomic.io/docs/usage/plugins/
feedsOptions: {
title: pkg.name,
Expand Down
2 changes: 1 addition & 1 deletion src/builder/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import webpack from "./webpack"
import sortAssets from "./webpack/sortAssets"
import devServer from "./server"

import collection from "../phenomic-loader/cache"
import collection from "../loader/cache"

import webpackConfigBrowser from "./webpack/config.browser.js"
import webpackConfigNode from "./webpack/config.node.js"
Expand Down
4 changes: 2 additions & 2 deletions src/builder/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import opn from "opn"
import debug from "debug"
import portFinder from "portfinder"

import minifyCollection from "../phenomic-loader/minify"
import minifyCollection from "../loader/minify"
import serialize from "../_utils/serialize"

import collection from "../phenomic-loader/cache.js"
import collection from "../loader/cache.js"
import pathToUri from "../_utils/path-to-uri"

const log = debug("phenomic:builder:server")
Expand Down
2 changes: 1 addition & 1 deletion src/builder/webpack/config.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default (config: PhenomicConfig): WebpackConfig => {
...webpackConfig.externals || defaultExternals,

// we need this to be the same between the entire node runtime
"phenomic/lib/phenomic-loader/cache",
"phenomic/lib/loader/cache",
],

// sourcemaps
Expand Down
18 changes: 1 addition & 17 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,4 @@ export { default as PageContainer } from "./components/PageContainer"
export { default as BodyContainer } from "./components/BodyContainer"
export { default as joinUri } from "url-join"

export const phenomicLoader = "phenomic/lib/phenomic-loader"

/* eslint-disable max-len */
export const phenomicLoaderPlugins = {
initBodyPropertyFromContent: require("./phenomic-loader-plugin-init-body-property-from-content").default,
initHeadPropertyFromConfig: require("./phenomic-loader-plugin-init-head-property-from-config").default,
initHeadPropertyFromContent: require("./phenomic-loader-plugin-init-head-property-from-content").default,
initRawPropertyFromContent: require("./phenomic-loader-plugin-init-raw-property-from-content").default,
initRawBodyPropertyFromContent: require("./phenomic-loader-plugin-init-rawBody-property-from-content").default,
markdownInitHeadDescriptionPropertyFromContent: require("./phenomic-loader-plugin-markdown-init-head.description-property-from-content").default,
markdownTransformBodyPropertyToHtml: require("./phenomic-loader-plugin-markdown-transform-body-property-to-html").default,
}

export const phenomicLoaderPresets = {
default: require("./phenomic-loader-preset-default").default,
markdown: require("./phenomic-loader-preset-markdown").default,
}
export const phenomicLoader = "phenomic/lib/loader"
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// @flow

import initHeadPropertyFromConfig
from "../phenomic-loader-plugin-init-head-property-from-config"
from "../loader-plugin-init-head-property-from-config"
import initHeadPropertyFromContent
from "../phenomic-loader-plugin-init-head-property-from-content"
from "../loader-plugin-init-head-property-from-content"
import initBodyPropertyFromContent
from "../phenomic-loader-plugin-init-body-property-from-content"
from "../loader-plugin-init-body-property-from-content"

export default [
// $FlowFixMe Missing annotation wtf?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// @flow

import defaultPlugins from "../phenomic-loader-preset-default"
import defaultPlugins from "../loader-preset-default"

import initHeadDescriptionPropertyFromContent
// eslint-disable-next-line max-len
from "../phenomic-loader-plugin-markdown-init-head.description-property-from-content"
from "../loader-plugin-markdown-init-head.description-property-from-content"
import transformBodyPropertyToHtml
from "../phenomic-loader-plugin-markdown-transform-body-property-to-html"
from "../loader-plugin-markdown-transform-body-property-to-html"

export default [
...defaultPlugins,
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import test from "ava"

import minify from "../minify"

test("phenomic/lib/phenomic-loader/minify", (t) => {
test("phenomic/lib/loader/minify", (t) => {
t.deepEqual(
minify([
{
Expand Down
File renamed without changes.
File renamed without changes.
3 changes: 1 addition & 2 deletions src/phenomic-loader/index.js → src/loader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import path from "path"
import loaderUtils from "loader-utils"
import frontMatterParser from "gray-matter"
import colors from "chalk"

import pathToUri from "../_utils/path-to-uri"
import urlify from "../_utils/urlify"
Expand All @@ -23,7 +22,7 @@ module.exports = function(input: string) {
const context = options.context || webpackInstance.options.context
const plugins = (
options.plugins ||
require("../phenomic-loader-preset-markdown").default
require("../loader-preset-markdown").default
)

const relativePath = path.relative(context, webpackInstance.resourcePath)
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/static/to-html/url-as-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import Html from "./Html"
import PhenomicContextProvider from "../../components/ContextProvider"
import serialize from "../../_utils/serialize"

import minifyCollection from "../../phenomic-loader/minify"
import minifyCollection from "../../loader/minify"

export default function(
url: string,
Expand Down
2 changes: 1 addition & 1 deletion themes/phenomic-theme-base/webpack.config.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export const makeConfig = (config = {}) => {

phenomic: {
context: path.join(__dirname, config.source),
// plugins: [ ...phenomicLoaderPresets.markdown ]
// plugins: [ ...require("phenomic/lib/loader-preset-markdown").default ]
// see https://phenomic.io/docs/usage/plugins/
feedsOptions: {
title: pkg.name,
Expand Down

0 comments on commit 08bd04f

Please sign in to comment.