Skip to content

Commit

Permalink
feat: move to prism
Browse files Browse the repository at this point in the history
  • Loading branch information
remy committed Aug 24, 2018
1 parent cba1e66 commit e5e446f
Show file tree
Hide file tree
Showing 8 changed files with 301 additions and 30 deletions.
3 changes: 2 additions & 1 deletion public/_partials/layout.jade
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ else
//- style(critical)
//- include ../css/critical.css
link(rel="stylesheet" href="/css/prism.css")
link(rel="stylesheet" href="/css/screen.css?#{version}")
script
| try {
Expand Down Expand Up @@ -128,7 +129,7 @@ else
//- link(rel="stylesheet" href="/css/screen.css?#{version}")
script(src="/js/jquery.min.js")
script(src="/js/jquery.fitvids.js")
script(src="/js/highlight.min.js")
script(src="/js/prism.js")
script(src="/js/permalink.js?#{version}")
script(src="/js/index.js?#{version}")

Expand Down
8 changes: 5 additions & 3 deletions public/css/mq.less
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@
padding: 10px;
}

code {
code,
code[class*="language-"] {
font-size: 0.8rem;
}

Expand Down Expand Up @@ -93,7 +94,8 @@
}
}

pre {
pre,
pre[class*="language-"] {
margin-left: -10px;
padding-left: 5px;
border-radius: 0;
Expand All @@ -105,7 +107,7 @@
}
}

pre code.hljs {
pre code[class*="language-"] {
padding-top: 20px;
padding-bottom: 20px;
padding-right: 20px;
Expand Down
141 changes: 141 additions & 0 deletions public/css/prism.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/* PrismJS 1.15.0
https://prismjs.com/download.html#themes=prism&languages=markup+css+clike+javascript+bash+diff+markup-templating+json+markdown+makefile+nginx+php */
/**
* prism.js default theme for JavaScript, CSS and HTML
* Based on dabblet (http://dabblet.com)
* @author Lea Verou
*/

code[class*="language-"],
pre[class*="language-"] {
color: black;
background: none;
text-shadow: 0 1px white;
font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
text-align: left;
white-space: pre;
word-spacing: normal;
word-break: normal;
word-wrap: normal;
line-height: 1.5;

-moz-tab-size: 4;
-o-tab-size: 4;
tab-size: 4;

-webkit-hyphens: none;
-moz-hyphens: none;
-ms-hyphens: none;
hyphens: none;
}

pre[class*="language-"]::-moz-selection, pre[class*="language-"] ::-moz-selection,
code[class*="language-"]::-moz-selection, code[class*="language-"] ::-moz-selection {
text-shadow: none;
background: #b3d4fc;
}

pre[class*="language-"]::selection, pre[class*="language-"] ::selection,
code[class*="language-"]::selection, code[class*="language-"] ::selection {
text-shadow: none;
background: #b3d4fc;
}

@media print {
code[class*="language-"],
pre[class*="language-"] {
text-shadow: none;
}
}

/* Code blocks */
pre[class*="language-"] {
padding: 1em;
margin: .5em 0;
overflow: auto;
}

:not(pre) > code[class*="language-"],
pre[class*="language-"] {
background: #f5f2f0;
}

/* Inline code */
:not(pre) > code[class*="language-"] {
padding: .1em;
border-radius: .3em;
white-space: normal;
}

.token.comment,
.token.prolog,
.token.doctype,
.token.cdata {
color: slategray;
}

.token.punctuation {
color: #999;
}

.namespace {
opacity: .7;
}

.token.property,
.token.tag,
.token.boolean,
.token.number,
.token.constant,
.token.symbol,
.token.deleted {
color: #905;
}

.token.selector,
.token.attr-name,
.token.string,
.token.char,
.token.builtin,
.token.inserted {
color: #690;
}

.token.operator,
.token.entity,
.token.url,
.language-css .token.string,
.style .token.string {
color: #9a6e3a;
background: hsla(0, 0%, 100%, .5);
}

.token.atrule,
.token.attr-value,
.token.keyword {
color: #07a;
}

.token.function,
.token.class-name {
color: #DD4A68;
}

.token.regex,
.token.important,
.token.variable {
color: #e90;
}

.token.important,
.token.bold {
font-weight: bold;
}
.token.italic {
font-style: italic;
}

.token.entity {
cursor: help;
}

43 changes: 27 additions & 16 deletions public/css/screen.less
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,23 @@ kbd {
margin: 0 4px;
}

code {
code,
code[class*="language-"] {
font-family: @code-font;
background: #f3f3f3;
padding: 2px;
font-size: 1rem;
border-radius: 2px;
}

// resetting prism
code[class*="language-"],
pre[class*="language-"] {
font-family: @code-font;
background: #f3f3f3;
text-shadow: none;
}

a:hover code,
a:focus code {
color: black;
Expand All @@ -161,14 +170,16 @@ a:focus code {
background: lighten(@code-background, 60%);
}

pre code {
pre code,
pre[class*="language-"] code {
color: @code-foreground;
background: @code-background;
padding: 0.5em;
-webkit-text-size-adjust: none;
}

pre {
pre,
pre[class*="language-"] {
padding: 0 0.2em;
font-family: @code-font;
margin: 10px 0;
Expand Down Expand Up @@ -1212,21 +1223,21 @@ img[title^="Sample"] {

@import (less) 'mq.less';
// // code font highlight
@import (inline) 'github.css';
// @import (inline) 'github.css';

@import (less) 'form.less';


.hljs {
background: transparent;
}
// .hljs {
// background: transparent;
// }

.coffeescript .javascript,
.javascript .xml,
.tex .hljs-formula,
.xml .javascript,
.xml .vbscript,
.xml .css,
.xml .hljs-cdata {
opacity: 0.65;
}
// .coffeescript .javascript,
// .javascript .xml,
// .tex .hljs-formula,
// .xml .javascript,
// .xml .vbscript,
// .xml .css,
// .xml .hljs-cdata {
// opacity: 0.65;
// }
111 changes: 108 additions & 3 deletions public/drafts/ive-been-doing-reduce-wrong.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,46 @@
# I've been doing reduce wrong!
# Increasing reduce with spread

There's something I find particularly pleasing about chaining my code. I enjoyed it when I wrote a lot of jQuery, and even prior to jQuery, I remember feeling like it was a code super power that I could chain function calls together in JavaScript.

It stands to reason that with arrow functions and a handful of array methods, my inner chaining unicorn is free to run wild. Except, in my case, when I use `Array.reduce` I typically drop into a multi-line function, ugh!

<!--more-->

## Prior use
## Prior art

I've found that I have a lot of this type of `reduce` in my code:

```js
return input.reduce((acc, curr) => {
acc[curr] = altSource[curr];
return acc;
}, {});
```

And this:

```js
return input.reduce((acc, curr) => {
acc.push(curr);
return acc;
}, []);
```

Or this, as a poor way to dedupe:

```js
return input.reduce((acc, curr) => {
if (!acc.includes(curr)) {
acc.push(curr);
}

return acc;
}, []);
```

_Note that these variables are simplified - but it is the same two lines over and over._


I ran a grep (using `ag`) and I found a lot of this:

To get my chaining all sleek looking, it wants to be in a single line, so what I need are operations that return the updated result. So `Array.push` is off the list for instance.

Expand Down Expand Up @@ -36,3 +68,76 @@ Object.keys(process.env).reduce((acc, curr) =>
acc.set(curr, JSON.stringify(process.env[curr])),
new Map())
```

---

Instead of:

```js
const props = Object.getOwnPropertyNames(this).reduce((acc, curr) => {
if (!curr.startsWith('_')) {
acc[curr] = this[curr];
}
return acc;
}, {});
```

Should be:

```js
const props = Object.getOwnPropertyNames(this)
.filter(k => !k.startsWith('_'))
.reduce((acc, curr) => ({ ...acc, [curr]: this[curr] }), {});
```

---

But sometimes being verbose is okay.

For instance, this:

```js
const config = {
"snippets.javascript": {
"cl": "console.log($0);",
"fn": "() => { $0 }"
},
"snippets.css": {},
"snippets.html": {}
};

const res = Object.keys(res).reduce((acc, curr) => {
const [store, key] = curr.split('.');

if (!acc[store]) acc[store] = {};
acc[store][key] = config[curr];
return acc;
}, {});
```

Makes the following object:

```json
{
"snippets": {
"javascript": {
"cl": "console.log($0);",
"fn": "() => { $0 }"
},
"css": {},
"html": {}
}
}
```

_Could be_ rewritten as:

```js
const res = Object.keys(config)
.map(k => [ ...k.split('.'), k ])
.reduce((acc, [store, key, target]) => (
{ ...acc, [store]: { ...(acc[store] || {}), [key]: config[target] } }
), {});
```

Which is pretty much illegible.
Loading

0 comments on commit e5e446f

Please sign in to comment.