jekyll blog new line (minimal-mistake) - yaml

jekyll blog(minimal-mistakes thema) has a space to introduce myself.
I want to write on two lines in this space.
For example
hello
world
I know that to edit this page, i need to touch the _config.yml file.
# Site Author
author:
name : "Choi Young-jin"
avatar : "/assets/images/images/avatar.png"
bio : "**^^**" <-----------Parts to change
42 intra ID: yochoi
location : "Seoul"
email : "amateur.toss#gmail.com"
links:
- label: "Email"
icon: "fas fa-fw fa-envelope-square"
# url: "amateur.toss#gmail.com"
- label: "GitHub"
icon: "fab fa-fw fa-github"
url: "https://github.com/amateurtoss"
The escape character does not work.
bio: "hello\nworld"
What if I want to show the string in two lines?

Well it's markdown, so you should do
bio: |-
hello
world
(That's a YAML block scalar, which is interpreted literally and ends with the next item on the same or lesser indentation level as bio)
You can of course also do
bio: "hello\n\nworld"
But it's less obvious what happens here.

You can use HTML in the bio string, so you can simply use a HTML linebreak:
bio: "hello<br>world"
The above is the only way in which I managed to have a single line break. All other options lead to either no line break or an empty line between the two lines.

Related

Specifying parameters in yml file for Quarto

I am creating a quarto book project in RStudio to render an html document.
I need to specify some parameters in the yml file but the qmd file returns
"object 'params' not found". Using knitR.
I use the default yml file where I have added params under the book tag
project:
type: book
book:
title: "Params_TEst"
author: "Jane Doe"
date: "15/07/2022"
params:
pcn: 0.1
chapters:
- index.qmd
- intro.qmd
- summary.qmd
- references.qmd
bibliography: references.bib
format:
html:
theme: cosmo
pdf:
documentclass: scrreprt
editor: visual
and the qmd file looks like this
# Preface {.unnumbered}
This is a Quarto book.
To learn more about Quarto books visit <https://quarto.org/docs/books>.
```{r}
1 + 1
params$pcn
When I render the book, or preview the book in Rstudio the error I receive is:
Quitting from lines 8-10 (index.qmd)
Error in eval(expr, envir, enclos) : object 'params' not found
Calls: .main ... withVisible -> eval_with_user_handlers -> eval -> eval
I have experimented placing the params line in the yml in different places but nothing works so far.
Could anybody help?
For multi-page renders, e.g. quarto books, you need to add the YAML to each page, not in the _quarto.yml file
So in your case, each of the chapters that calls a parameter needs a YAML header, like index.qmd, intro.qmd, and summary.qmd, but perhaps not references.qmd.
The YAML header should look just like it does in a standard Rmd. So for example, your index.qmd would look like this:
---
params:
pcn: 0.1
---
# Preface {.unnumbered}
This is a Quarto book.
To learn more about Quarto books visit <https://quarto.org/docs/books>.
```{r}
1 + 1
params$pcn
But, what if you need to change the parameter and re-render?
Then simply pass new parameters to the quarto_render function
quarto::quarto_render(input = here::here("quarto"), #expecting a dir to render
output_format = "html", #output dir is set in _quarto.yml
cache_refresh = TRUE,
execute_params = list(pcn = 0.2))
For now, this only seems to work if you add the parameters to each individual page front-matter YAML.
If you have a large number of pages and need to keep parameters centralized, a workaround is to run a preprocessing script that replaces the parameters in all pages. To add a preprocessing script, add the key pre-render to your _quarto.yml file. The Quarto website has detailed instructions.
For example, if you have N pages named index<N>.qmd, you could have a placeholder in the YML of each page:
---
title: This is chapter N
yourparamplaceholder
---
Your pre-render script could replace yourparamplaceholder with the desired parameters. Here's an example Python script:
for filename in os.listdir(dir):
if filename.endswith(".qmd"):
with open(filename, "r") as f:
txt = f.read()
f.replace('yourparamplaceholder', 'params:\n\tpcn: 0.1\n\tother:20\n')
with open(filename, "w") as ff:
ff.write(txt)
I agree with you that being able to set parameters centrally would be a good idea.

YML syntax error

I want to have a multi-line bit of markdown java in a yam file. I tried many things but I guess I don't quite get the quoting rules of Yaml.
{
title: Museum,
body: |
"```java
code code code
java2",
answers: [
"`museum`",
"`museum.getFloor(3)`",
"`museum.getFloor(3).getExhibit(5)`",
"`museum.getFloor(3).getExhibit(5).getCurator()`",
"`museum.getFloor(3).getExhibit(5).getCurator().name`",
"`museum.getFloor(3).getExhibit(5).getCurator().name.toUpper()`"
]
}
Produces:
/Users/pitosalas/.rbenv/versions/2.3.1/lib/ruby/2.3.0/psych.rb:377:in `parse': (generator/test.yml): found character that cannot start any token while scanning for the next token at line 3 column 9 (Psych::SyntaxError)
YAML has two styles: the JSON like flow style and the much better human readable block style.
Roughly speaking you can have nested structures each style nested within itself and can have flow style nested within block style, but block style nested within flow style is not allowed.
Your to level { and } are flow style but you try to introduce, with |, a literal block style scalar within that flow style. Replace the flow style with block style upwards from that scalar:
title: Museum
body: |
"```java
code code code
java2"
answers: [
"`museum`",
"`museum.getFloor(3)`",
"`museum.getFloor(3).getExhibit(5)`",
"`museum.getFloor(3).getExhibit(5).getCurator()`",
"`museum.getFloor(3).getExhibit(5).getCurator().name`",
"`museum.getFloor(3).getExhibit(5).getCurator().name.toUpper()`"
]
and your YAML is fine. Note that the double quotes "around" the value for the key body are not going to be stripped when loading, maybe that is not what you intended.
You should IMO not leave out the trailing , after the last value in the (flow style) sequence that is the value for answers. This will certainly lead to errors when you extend the list and forget to put in the trailing comma on the line above.
I would personally go for block style all the way:
title: Museum
body: |
"```java
code code code
java2"
answers:
- "`museum`"
- "`museum.getFloor(3)`"
- "`museum.getFloor(3).getExhibit(5)`"
- "`museum.getFloor(3).getExhibit(5).getCurator()`"
- "`museum.getFloor(3).getExhibit(5).getCurator().name`"
- "`museum.getFloor(3).getExhibit(5).getCurator().name.toUpper()`"
When dealing with YAML file generation that is convoluted or complex, or when it's not working as I expect, I revert to letting Ruby show me the way:
require 'yaml'
body = <<EOT
"```java
code code code
java2
"
EOT
answers = %w(
`museum`
`museum.getFloor(3)`
`museum.getFloor(3).getExhibit(5)`
`museum.getFloor(3).getExhibit(5).getCurator()`
`museum.getFloor(3).getExhibit(5).getCurator().name`
`museum.getFloor(3).getExhibit(5).getCurator().name.toUpper()`
)
obj = {
"title" => "Museum",
"body" => body,
"answers" => answers
}
puts obj.to_yaml
Which, in this case, outputs:
---
title: Museum
body: |
"```java
code code code
java2
"
answers:
- "`museum`"
- "`museum.getFloor(3)`"
- "`museum.getFloor(3).getExhibit(5)`"
- "`museum.getFloor(3).getExhibit(5).getCurator()`"
- "`museum.getFloor(3).getExhibit(5).getCurator().name`"
- "`museum.getFloor(3).getExhibit(5).getCurator().name.toUpper()`"
If you then pass that YAML back into the parser, you should get the original data structure back:
YAML.load(obj.to_yaml)
# => {"title"=>"Museum",
# "body"=>"\"```java\n" +
# "code code code\n" +
# "java2\n" +
# "\"\n",
# "answers"=>
# ["`museum`",
# "`museum.getFloor(3)`",
# "`museum.getFloor(3).getExhibit(5)`",
# "`museum.getFloor(3).getExhibit(5).getCurator()`",
# "`museum.getFloor(3).getExhibit(5).getCurator().name`",
# "`museum.getFloor(3).getExhibit(5).getCurator().name.toUpper()`"]}

In rancher-compose.yml , questions variable use type string default include $ cann't start

I use rancher, when rancher-compose input $, it can't create stack
- variable: vzdb_rule
description: "this line will use regular expression in rancher-compose.yml"
label: "regular expression"
default: ^$
required: true
type: "string"
If I'm understanding correctly, you will want to use
$$ to get $ in the final yaml file. For example, in rancher compose we have labels with ${stack_name}/${service_name}.. in compose they look like:
$${stack_name}/$${service_name}
You don't need to escape $, it is not a reserved character in YAML.
Your example is not a correct YAML file, you cannot indent description differently from variable if they are keys to the same mapping (which they are).
If you align your keys things load fine:
import ruamel.yaml
from ruamel.yaml.util import load_yaml_guess_indent
yaml_str = """\
- variable: vzdb_rule
description: "In line with the rules of the real-time encoding library of regular expressions"
label: "实时库编码规则1"
default: ^$
required: false
type: "string"
"""
data = ruamel.yaml.round_trip_load(yaml_str)
print(ruamel.yaml.round_trip_dump(data))
gives:
- variable: vzdb_rule
description: In line with the rules of the real-time encoding library of regular expressions
label: 实时库编码规则1
default: ^$
required: false
type: string

RubyMine RoR I18n config/locals/en.yml syntax error "file should have single root"

I don't know if this is just a goof syntax error, or if this is something I should legitimately be concerned about. I've searched online for this error and have found very little concerning it. So my guess is that this is either something so "no duh" that hardly anybody ends up with this error, or that it's so obscure that - again - hardly anybody ends up with it. Nonetheless, here we go:
This is what I'm using:
Ruby 2.1.1p76
Rails 4.0.5
SafeYAML 1.0.3
RubyMine 6.3
[should you need anymore information, please ask]
The error I'm getting exactly is: "Rails i18n locale file should have single root"
Here is a shortened version of my en.yml file (I'll include what I believe to be the problem areas)
<%
object_names = **{**
:administrator => 'Administrator',
:activity_log => 'Site Activity',
:answer => 'Answer',
:approval => 'Approval',
:user => 'Member',
:video => 'Video',
:vote => 'Like'
}
section_names = **{**
:approvals => 'Items Awaiting Review',
:advertisements => 'Advertisements',
:ad_placements => 'Ad Placements',
:awarded_badges => 'Badges',
:badges => 'Badges',
:videos => 'Videos'
}
anonymous = 'Anonymous**'
%>
en:
homepage:
mine: "My %{site_name}"
site_name: "%{site_name}"
site_condition_name: "%{site_condition_name}"
titles:
main: "%{site_name}"
delimiters:
minor:** ' **-** '
major: ' | '
scopes:
popular: Popular
newest: Newest
active: Active
my_feed: My Friends
my_activity: What I've Done
tracked_items: "Only <%= object_names[:tracked_item].pluralize %>"
everyone: Everyone
user: "By %{name}"
view: "By %{view}"
sent: "Sent <%= object_names[:message].pluralize %>"
page: "Page %{page}"
letter: "Starting With %{letter}"
query: "%{query}"
category: "%{category}"
**meta_description:**
main: "%{site_name} is a social network that connects people"
footer:
about: "About %{site_name}"
about_alliance_health: About Alliance Health
community_advocates: Community Advocates
terms_of_use: Terms of Use
oh - wow. Ok, it looks like bold isn't going to work inside the code markers. But I'm sure you guys can decipher what's going on. Basically anything that's bold (or delimited with a double asterisk '**') is where the IDE is marking the code with this particular error. So, as you can see, it seems rather chaotic and nonsensical. But I often find that when such things happen, it's usually one tiny little character somewhere that's throwing everything else off.
Now, I'm no YAML expert - in fact, I hardly even know the stuff (which is something I'm planning on changing here in the near future) so this may be something along the "no duh" lines. However, it is interesting to note that the bulk of the error-marked syntax starts with the last single-quote of the word: " 'anonymous' ", all the way down to: " minor: ", skipping the first following single quote, and picking up again on the hyphen, afterwhich there are no more errors for the rest of the nearly 5,500 lines of this file.
Thanks to anybody who helps out. I've been dorking around with this for far too long, and with very little online information on this particular issue. So any help is much appreciated :)
Thanks!
So - I'm not sure this will ever help anybody ... but in the case that it may, this is how I re-engineered the script to avoid the errors. I simply removed the usual delimiters that were causing the parsing confusion. And #mu is too short, you were correct. This is an erb.yml file, though I'm not sure why the original creator left the dual extension off. At any rate - thank you to everybody who offered any suggestions and ideas :)
<%
object_names = Hash.new
object_names[:administrator] = %q<Administrator>
object_names[:activity_log] = %q<Site Activity>
object_names[:answer] = %q<Answer>
object_names[:approval] = %q<Approval>
object_names[:user] = %q<Member>
object_names[:video] = %q<Video>
object_names[:vote] = %q<Like>
section_names = Hash.new
section_names[:approvals] = %q<Items Awaiting Review>
section_names[:advertisements] = %q<Advertisements>
section_names[:ad_placements] = %q<Ad Placements>
section_names[:awarded_badges] = %q<Badges>
section_names[:badges] = %q<Badges>
section_names[:videos] = %q<Videos>
%>
en:
homepage:
mine: "My %{site_name}"
site_name: "%{site_name}"
site_condition_name: "%{site_condition_name}"
titles:
main: "%{site_name}"
delimiters:
minor: ' - '
major: ' | '
scopes:
popular: Popular
newest: Newest
active: Active
my_feed: My Friends
my_activity: What I've Done
tracked_items: "Only <%= object_names[:tracked_item].pluralize %>"
everyone: Everyone
user: "By %{name}"
view: "By %{view}"
sent: "Sent <%= object_names[:message].pluralize %>"
page: "Page %{page}"
letter: "Starting With %{letter}"
query: "%{query}"
category: "%{category}"
meta_description:
main: "%{site_name} is a social network that connects people"
footer:
about: "About %{site_name}"
about_alliance_health: About Alliance Health
community_advocates: Community Advocates
terms_of_use: Terms of Use

What kind of data structure is this?

I am pulling recent commits from github and trying to parse it using ruby. I know that I can parse it manually but I wanted to see if there was some package that could turn this into a hash or another data structure.
commits:
- parents:
- id: 202fb79e8686ee127fe49497c979cfc9c9d985d5
author:
name: This guy
login: tguy
email: tguy#tguy.com
url: a url
id: e466354edb31f243899051e2119f4ce72bafd5f3
committed_date: "2010-07-19T13:44:43-07:00"
authored_date: "2010-07-19T13:33:26-07:00"
message: |-
message
- parents:
- id: c3c349ec3e9a3990cac4d256c308b18fd35d9606
author:
name: Other Guy
login: oguy
email: oguy#gmail.com
url: another url
id: 202fb79e8686ee127fe49497c979cfc9c9d985d5
committed_date: "2010-07-19T13:44:11-07:00"
authored_date: "2010-07-19T13:44:11-07:00"
message: this is another message
This is YAML http://ruby-doc.org/core/classes/YAML.html. You can do something like obj = YAML::load yaml_string (and a require 'yaml' at the top of your file, its in the standard libs), and then access it like a nested hash.
YAML is basically used in the ruby world the way people use XML in the java/c# worlds.
Looks like YAML to me. There are parsers for a lot of languages. For example, with the YAML library included with Ruby:
data = <<HERE
commits:
- parents:
- id: 202fb79e8686ee127fe49497c979cfc9c9d985d5
author:
name: This guy
login: tguy
email: tguy#tguy.com
url: a url
id: e466354edb31f243899051e2119f4ce72bafd5f3
committed_date: "2010-07-19T13:44:43-07:00"
authored_date: "2010-07-19T13:33:26-07:00"
message: |-
message
- parents:
- id: c3c349ec3e9a3990cac4d256c308b18fd35d9606
author:
name: Other Guy
login: oguy
email: oguy#gmail.com
url: another url
id: 202fb79e8686ee127fe49497c979cfc9c9d985d5
committed_date: "2010-07-19T13:44:11-07:00"
authored_date: "2010-07-19T13:44:11-07:00"
message: this is another message
HERE
pp YAML.load data
It prints:
{"commits"=>
[{"author"=>{"name"=>"This guy", "login"=>"tguy", "email"=>"tguy#tguy.com"},
"parents"=>[{"id"=>"202fb79e8686ee127fe49497c979cfc9c9d985d5"}],
"url"=>"a url",
"id"=>"e466354edb31f243899051e2119f4ce72bafd5f3",
"committed_date"=>"2010-07-19T13:44:43-07:00",
"authored_date"=>"2010-07-19T13:33:26-07:00",
"message"=>"message"},
{"author"=>
{"name"=>"Other Guy", "login"=>"oguy", "email"=>"oguy#gmail.com"},
"parents"=>[{"id"=>"c3c349ec3e9a3990cac4d256c308b18fd35d9606"}],
"url"=>"another url",
"id"=>"202fb79e8686ee127fe49497c979cfc9c9d985d5",
"committed_date"=>"2010-07-19T13:44:11-07:00",
"authored_date"=>"2010-07-19T13:44:11-07:00",
"message"=>"this is another message"}]}
This format is YAML, but you can get the same information in XML or JSON, see General API Information. I'm sure there are libraries to parse those formats in Ruby.
Although this isn't exactly what you're looking for, here's some more info on pulling commits. http://develop.github.com/p/commits.html. Otherwise, I think you may just need to manually parse it.

Resources