ardumont / org2jekyll

Blogging with org-mode and jekyll without alien yaml headers.
GNU General Public License v2.0
71 stars 19 forks source link

is it possible to add freeform extra yaml headers? 2/2 #36

Closed yefeiyu closed 8 years ago

yefeiyu commented 8 years ago

Thank you for your last replay! Today I study the "monkey patch", and I DO step by step like this: 1rt step: I paste the patch to my "~/.emacs.d/init.d/blog-pack.el":

(custom-set-variables '(org2jekyll-extra-yaml-headers "scheme-text: \"#0029ff\"
scheme-link: \"#ff00b4\"
scheme-hover: \"#ff00b4\"
scheme-code: \"#ad00ff\"
scheme-bg: \"#00ebff\"
scheme-hero-text: \"#00ebff\"
scheme-hero-link: \"#00ebff\"
scheme-hero-bg: \"#0029ff\"
plugin: lightense"))

2nd step: Press "Alt+Shift+;", then mini buffer appear the word "Eval:", then I paste that two patches what you give me,

(defcustom org2jekyll-extra-yaml-headers nil
  "An entry of static yaml header (already formatted).
E.g. from https://github.com/ardumont/org2jekyll/issues/34#issue-148684715:
scheme-text: \"#0029ff\"
scheme-link: \"#ff00b4\"
scheme-hover: \"#ff00b4\"
scheme-code: \"#ad00ff\"
scheme-bg: \"#00ebff\"
scheme-hero-text: \"#00ebff\"
scheme-hero-link: \"#00ebff\"
scheme-hero-bg: \"#0029ff\"
plugin: lightense"
  :group 'org2jekyll)

(defun org2jekyll--to-yaml-header (org-metadata)
  "Given a list of ORG-METADATA, compute the yaml header string."
  (-let (((begin end) (if (org2jekyll--old-org-version-p)
                          '("#+BEGIN_HTML" "#+END_HTML\n")
                        '("#+BEGIN_EXPORT HTML" "#+END_EXPORT\n"))))
    (--> org-metadata
         org2jekyll--org-to-yaml-metadata
         (--map (format "%s: %s" (car it) (cdr it)) it)
         (cons "---" it)
         (cons begin it)
         (-snoc it org2jekyll-extra-yaml-headers)
         (-snoc it "---")
         (-snoc it end)
         (s-join "\n" it)
         (s-replace "\n\n" "\n" it))))

3nd step: I built an "org" file:

#+STARTUP: showall
#+STARTUP: hidestars
#+OPTIONS: H:2 num:nil tags:nil toc:nil timestamps:t
#+LAYOUT: post
#+AUTHOR: yefeiyu
#+DATE: 2016-04-18 一 15:14
#+TITLE: try
#+DESCRIPTION: 
#+TAGS: 
#+CATEGORIES: 

* try

4rd step: M-x org2jekyll-publish

5th step: Then It created a file of "2016-04-16-try.html",


---
layout: post
title: try
date: 2016-04-18
categories: 
-
tags: 
-
author: yefeiyu
excerpt: 

---

<div id="outline-container-sec-1" class="outline-2">
<h2 id="sec-1">one</h2>
<div class="outline-text-2" id="text-1">
<p>
try<br >
</p>
</div>
</div>

6th step: I didn't find the HEAD of "scheme-text ......", I had to paste it.

What's wrong with me ?


Although your patches are close to my target, but my goal is : 1, Input the "scheme-text ...." in ".org" file; 2, Create the ".html" file with backgroud color, text color and link color.

(btw: My last issue lack of "#ff3dss", only because I want fill the vacant position at every post, so the every article has it own color. My english is poor, I am sorry.)

Thank you!

ardumont commented 8 years ago

duplicate #34

ardumont commented 8 years ago

Hello,

Thanks for the clarification and the ``` quotes use, it's clearer ^^. You did not have to open a new issue though.

My english is poor, I am sorry.)

No worries, i understand and if i don't, i'll ask to clarify.

What's wrong with me ?

You need to apply the 2nd step before the first step. Because it installs what's used in your first step. And, in the first step, you also need to evaluate it with M-:.

That's why nothing appeared on your side.

Remark The lisp code i provided you with is just text. As long as it is not evaluated, it does nothing. That's why i ask you to evaluate (which is an install step of sort).

Although your patches are close to my target, but my goal is : 1, Input the "scheme-text ...." in ".org" file; 2, Create the ".html" file with backgroud color, text color and link color.

Ok, so what you are saying is that this custom i provided you with is not enough. The need is to permit to install some specific yaml on a per publish page/post basis, is that correct?

yefeiyu commented 8 years ago

You need to apply the 2nd step before the first step. Because it installs what's used in your first step. And, in the first step, you also need to evaluate it with M-:.

What's your mean is "To install that patch thought M-: paste-previous-snippet RET", and then patched the second part (custom-set-variables '(org2jekyll-extra-yaml-headers "scheme-text: \"#0029ff\".... also by "M-: paste-snippet RET", too? If I did so, but when I pressed "RET", it's appear "nil". I don't know how to deal with the 2nd step.

(custom-set-variables '(org2jekyll-extra-yaml-headers "scheme-text: \"#0029ff\"
scheme-link: \"#ff00b4\"
scheme-hover: \"#ff00b4\"
scheme-code: \"#ad00ff\"
scheme-bg: \"#00ebff\"
scheme-hero-text: \"#00ebff\"
scheme-hero-link: \"#00ebff\"
scheme-hero-bg: \"#0029ff\"
plugin: lightense"))
yefeiyu commented 8 years ago

The article effect is http://sparanoid.com/lab/amsf/custom-color-scheme.html and, http://sparanoid.com/lab/amsf/custom-css.html

Each color control different, display effects are not the same. So we need to fill in the blanks color values every time, scheme-text: "#______".

ardumont commented 8 years ago

... too?

Yes

If I did so, but when I pressed "RET", it's appear "nil".

It's ok. We do not really care about that result (i would have asked if it was important). What we care about is that the value is set.

To check the value is set, just ask emacs what's its current value. To ask emacs, again: M-: org2jekyll-extra-headers RET This will return the value you set for the expression org2jekyll-extra-headers.

I don't know how to deal with the 2nd step.

If you evaluate (see answer before), you did it.

Then try to publish a draft post. You should have in the html the scheme-text, etc... appears alongside the other yaml.

The need is to permit to install some specific yaml on a per publish page/post basis, is that correct?

So we need to fill in the blanks color values every time, scheme-text: "#__".

This seems to confirm the previous question i asked.

yefeiyu commented 8 years ago

When I do M=: org2jekyll-extra-headers RET, I get:

Debugger entered--Lisp error: (void-variable org2jekyll-extra-headers)
  eval(org2jekyll-extra-headers nil)
  eval-expression(org2jekyll-extra-headers nil)
  funcall-interactively(eval-expression org2jekyll-extra-headers nil)
  call-interactively(eval-expression nil nil)
  command-execute(eval-expression)

Next, I install part2 with: M-: paste-previous-snippet RET

(custom-set-variables '(org2jekyll-extra-yaml-headers "scheme-text: \"#0029ff\"
scheme-link: \"#ff00b4\"
scheme-hover: \"#ff00b4\"
scheme-code: \"#ad00ff\"
scheme-bg: \"#00ebff\"
scheme-hero-text: \"#00ebff\"
scheme-hero-link: \"#00ebff\"
scheme-hero-bg: \"#0029ff\"
plugin: lightense"))

Then, When I do M=: org2jekyll-extra-headers RET, I get

eval-expression: Symbol’s value as variable is void: org2jekyll-extra-headers

or, I do 'M-: org2jekyll-extra-yaml-headers RET', the same result wiith up.

Of cause, the file 2016-04-17-aaa.html is

---
layout: post
title: ccc
date: 2016-04-18
categories: 
-
tags: 
-
author: yefeiyu
excerpt: 
---

<div id="outline-container-sec-1" class="outline-2">
<h2 id="sec-1"></h2>
</div>

It's faulure :-(

yefeiyu commented 8 years ago

( I'll sleep, see you tomorrow :-)

ardumont commented 8 years ago
eval-expression: Symbol’s value as variable is void: org2jekyll-extra-headers

Yes, i made a typo, i should have used org2jekyll-extra-yaml-headers. Sorry.

or, I do 'M-: org2jekyll-extra-yaml-headers RET', the same result wiith up.

That's strange. That should not be if you installed, as you said you did in the second step, the custom variable and the function adaptation.

And you must use that once you have installed the previous snippet.

( I'll sleep, see you tomorrow :-)

Good night. I think what i ask of you is too much.

I will release a new version with an updated readme about what to do. I have adapted the code according to what i understood of your need.

Cheers,

ardumont commented 8 years ago

I've merged a new release 0.1.9. So, forget about all our conversation ^^ (and sorry for the confusion)

Just, refresh your emacs package list, update your org2jekyll package to use the latest one (0.1.9).

And then try and use the EXTRA-YAML-HEADERS property described here. This one is for per-post or page needs.

The custom variable (i tried to make you test) does exist too but is for more global use. In your case, the buffer property is what you need.

Cheers,

yefeiyu commented 8 years ago

Thank you for your take care. Today I delet all packages in /elpa, and reinstall them, the project is good. But the extra-yaml-headers only appeared on ".html" files, such as :

---
layout: post
title: mo
date: 2016-04-19
categories: 
-
tags: 
-
author: yefeiyu
excerpt: 
theme: blah
plugin: lightense
scheme-hover: "#ff00b4"
---

<div id="outline-container-sec-1" class="outline-2">
<h2 id="sec-1"></h2>
</div>

The ".org" files still disappear extra-headers, `#+EXTRA-YAML-HEADERS: theme: blah\nplugin: lightense\nscheme-hover: \"#ff00b4\"':

#+STARTUP: showall
#+STARTUP: hidestars
#+OPTIONS: H:2 num:nil tags:nil toc:nil timestamps:t
#+LAYOUT: post
#+AUTHOR: yefeiyu
#+DATE: 2016-04-19 二 11:26
#+TITLE: mo
#+DESCRIPTION: 
#+TAGS: 
#+CATEGORIES: 

*
mo

Is it designed like this?

Could we make the #+EXTRA-YAML-HEADERS: in ".org" file automatically show at beginning?


Emacs has it own Colors List, which position is Edit-Text Properties-Display Colors. If we can use this system automatically, input the color name and the article recognize it immediatly, it will be a best thing.

ardumont commented 8 years ago

But the extra-yaml-headers only appeared on ".html" files, such as :

So, it does as entertained.

The ".org" files still disappear extra-headers, `#+EXTRA-YAML-HEADERS: theme: blah\nplugin:

I don't understand this sentence.

The EXTRA-YAML-HEADER buffer property is not shown in org2jekyll buffer at first (see below for the reason).

If you add it to have some more yaml exported alongside your post, then publish the page/post, those options are still there after publishing. Nothing is removed from the org buffer.

Could we make the #+EXTRA-YAML-HEADERS: in ".org" file automatically show at beginning?

It's the first time someone asks me for such use case. I thought it made sense to be able to add some more yaml. So I added a mean to have them. But it's optional for now (it's not shown as default).

Is it designed like this?

Yes, i did not change the default draft property (the one you showed).

Here, if you install the following function in your .emacs (and evaluate it in your current session with M-:):

(defun org2jekyll-user-add-extra-yaml-headers ()
  "Permit to input extra yaml headers."
  (interactive)
  (-when-let (extra-headers (read-input "Extra yaml headers (one-liner): "))
    (insert (format "#+EXTRA-YAML-HEADERS: %s" extra-headers))))

It will be simpler to add those extra headers: M-x org2jekyll-user-add-extra-yaml-headers RET paste-your-extra-yaml-headers-here.

Emacs has it own Colors List, which position is Edit-Text Properties-Display Colors. If we can use this system automatically, input the color name and the article recognize it immediatly, it will be a best thing.

I am not sure I understand fully what you mean. (When you assert something, it's a good thing to mention source with links. This helps in grasping more completely what you said)

In any case, org2jekyll is not about rendering, it's about:

Also, if you are not happy how things are changed, you could adapt the code to your need and then propose a pull-request for all to benefit. That's what i did with org2jekyll in the first place.

Cheers,

yefeiyu commented 8 years ago

The ".org" files still disappear extra-headers, `#+EXTRA-YAML-HEADERS: theme: blah\nplugin: I don't understand this sentence.

Sorry, I'd mistake the sentence. It's lack a word of "not".

I want to do is : when I create a new draft after org2jekyll-create-drafts, it's appear such:

#+STARTUP: showall
#+STARTUP: hidestars
#+OPTIONS: H:2 num:nil tags:nil toc:nil timestamps:t
#+LAYOUT: post
#+AUTHOR: yefeiyu
#+DATE: 2016-04-19 二 20:56
#+TITLE: c
#+DESCRIPTION: 
#+TAGS: 
#+CATEGORIES: 
#+EXTRA-YAML-HEADERS: theme: blah\nplugin: lightense\nscheme-text: ""\nscheme-link: ""\nscheme-hover: ""\nscheme-code: ""\nscheme-bg: ""\nscheme-hero-text: ""\nscheme-hero-link: ""\nscheme-hero-bg: ""\n

Now, I can do this by yasnippet. I created a new snippet in the ~/.emacs.d/snippets/org-mode fold:

# -*- mode: snippet -*-
# name: oc
# key: oc
# --
#+EXTRA-YAML-HEADERS: theme: blah\nplugin: lightense\nscheme-text: ""\nscheme-link: ""\nscheme-hover: ""\nscheme-code: ""\nscheme-bg: ""\nscheme-hero-text: ""\nscheme-hero-link: ""\nscheme-hero-bg: ""\n
$0

So I can add the #+EXTRA-YAML-HEADERS...etc easy. the only regret thing is it need my input oc TAB every time, in each article. (After this step, I can definned colors) Thank you again. It's very comfortable to use org2jekyll, and I'll introducing it to others.

ardumont commented 8 years ago

Now, I can do this by yasnippet. I created a new snippet in the ~/.emacs.d/snippets/org-mode fold:

Interesting. I need to take a look at yasnippet. Thanks.

So I can add the #+EXTRA-YAML-HEADERS...etc easy. the only regret thing is it need my input oc TAB every time, in each article. (After this step, I can definned colors)

Also, since this changes every time, you can try and write your own function.

Something like this can be a bootstrap:

(defun yefeiyu-read-extra-yaml-headers ()
  "Read some pre-formatted extra yaml headers from user.
Write the extra-headers at point."
  (interactive)
  (let ((theme (read-input "theme: "))
        (plugin (read-input "plugin: "))
        (scheme-text (read-input "scheme-text: "))
        (scheme-link (read-input "scheme-link: "))
        (scheme-hover (read-input "scheme-hover: "))
        (scheme-code (read-input "scheme-code: "))
        (scheme-bg (read-input "scheme-bg: "))
        (scheme-hero-text (read-input "scheme-hero-text: "))
        (scheme-hero-link (read-input "scheme-hero-link: "))
        (scheme-hero-bg (read-input "scheme-hero-bg: ")))
    (insert (format "#+EXTRA-YAML-HEADERS: theme: %s\\nplugin: %s\\nscheme-text: \"%s\"\\nscheme-link: \"%s\"\\nscheme-hover: \"%s\"\\nscheme-code: \"%s\"\\nscheme-bg: \"%s\"\\nscheme-hero-text: \"%s\"\\nscheme-hero-link: \"%s\"\\nscheme-hero-bg: \"%s\"\\n"
                    theme plugin scheme-text scheme-link scheme-hover scheme-code scheme-bg scheme-hero-text scheme-hero-link scheme-hero-bg))))

An improvment on the previous function would be to have some completion on possible themes (to avoid repeating too much). As a hint, here are some emacs functions to do such thing ido-completing-read (native), helm-comp-read (needs helm).

Thank you again. It's very comfortable to use org2jekyll

Thanks.

Cheers,