Here is my attempt so far. I realise that there may be other ways to do this.
But why is my call to split failing?
{% capture path %}
{{ page.url | remove: ".html" | remove_first:"/" }}
{% endcapture %}
{% capture breadcrumbs %}
{{ path | split:'/' }}
{% endcapture %}
{% for crumb in breadcrumbs %}
{{ crumb }} »
{% endfor %}
I am uploading this to github and just getting nothing.
I've never been able to get split to work properly either, but breadcrumbs are still possible. The following is adapted from my code in that answer (note the section that should be modified in the if statement and that this is the readable version and doesn't work precisely as expected).
{% capture url_parts %} {{ page.url | remove: "/index.html" | replace:'/'," " }}{% endcapture %}
{% capture num_parts %}{{ url_parts | number_of_words }}{% endcapture %}
{% assign previous="" %}
{% if num_parts == "0" %}
<Handle being at the top of the site (i.e. "site.com/") here>
{% else %}
{% for unused in page.content limit:num_parts %}
{% capture first_word %}{{ url_parts | truncatewords:1 | remove:"…"}}{% endcapture %}
{{ first_word }} »
{% capture url_parts %}{{ url_parts | remove_first:first_word }}{% endcapture %}
{% endfor %}
{% endif %}
If the user is at /a/b/c.html this will print a » b » c », if they are at /a/b/ (or equivalently /a/b/index.html) it will just print a » b ».
At least, it will be close to that: for a Markdown file there are too many newlines between each time first_word is printed, so they are considered separate paragraphs and the output will be (this isn't a problem in an HTML file, but then more tags are needed to make it work properly):
a »
b »
c »
This can be solved by putting the whole for loop on one line (this is the code that should be used):
{% capture url_parts %} {{ page.url | remove: "/index.html" | replace:'/'," " }}{% endcapture %}
{% capture num_parts %}{{ url_parts | number_of_words }}{% endcapture %}
{% assign previous="" %}
{% if num_parts == "0" %}
<Handle being at the top of the site (i.e. "site.com/") here>
{% else %}
{% for unused in page.content limit:num_parts %}{% capture first_word %}{{ url_parts | truncatewords:1 | remove:"..."}}{% endcapture %}{{ first_word }} »{% capture url_parts %}{{ url_parts | remove_first:first_word }}{% endcapture %}{% endfor %}
{% endif %}
(NB. the page.content in the for loop is just to give something to iterate over, the magic is done by the limit:num_parts. However, this means that if page.content has fewer paragraphs than num_parts not all breadcrumbs will appear, if this is likely one might define a site variable in _config.yml like breadcrumb_list: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] and use site.breadcrumb_list as the placeholder instead of page.content. (Lifted from my other answer.))
Here is an example (it doesn't use precisely the same code as above, but it's just a few little modifications, and it is in an HTML file, so the problem with new lines creating paragraphs is not there).
Related
I am trying to make a default value for CPU if its mentioned(if its not mentioned, i have handled that separately) value in values file is less than 5000m. I am trying this but I don't think I am doing it correctly.
Also, if I make the default value as 5000m and in my values file its mentioned just as 5. Would it be able to compare both?
resources:
requests:
{{- if .Values.resources.requests.cpu }}
cpu: {{ .Values.resources.requests.cpu }}
{{- end }}
{{- if .Values.resources.requests.memory }}
memory: {{ .Values.resources.requests.memory }}
{{- end }}
limits:
{{- if ((( .Values.resources).limits).cpu) }}
cpu: {{ .Values.resources.limits.cpu }}
{{- else }}
{{- $limit_value := .Values.resources.requests.cpu | toString | regexFind "[0-9.]+" }}
{{- $limit_suffix := .Values.resources.requests.cpu | toString | regexFind "[^0-9.]+" }}
cpu: {{ mulf $limit_value 3 }}{{ $limit_suffix }} }}
{{- end }}
{{- if (((.Values.resources).limits).memory) }}
memory: {{ .Values.resources.limits.memory }}
{{- else }}
{{- $limit_val := .Values.resources.requests.memory | toString | regexFind "[0-9.]+" }}
{{- $limit_suff := .Values.resources.requests.memory | toString | regexFind "[^0-9.]+" }}
memory: {{ mulf $limit_val 3 }}{{ $limit_suff }}
{{- end }}
{{- end }}
You have two separate issues here. There's not a built-in way to parse the Kubernetes resource values, so you'll have to do a lot of work to actually provide that default value.
If you just want to provide a default value and not try to check for a minimum, then you can just use the Helm (Sprig) default function:
resources:
requests:
cpu: {{ .Values.resources.requests.cpu | default "5000m" }}
The minimum bound is what leads to some trouble. I don't believe there's a function in Helm to parse 5000m, or to compare that to 5.0. You could try writing it in Helm template syntax, but it can become awkward.
{{/* Convert a resource quantity like "5000m" to a base number like "5".
Call with the quantity string as the parameter, returns the number
as a string. */}}
{{- define "resource-quantity" -}}
{{- if . | hasSuffix "m" -}}
{{- $quantity = . | trimSuffix "m" | float64 -}}
{{- divf $quantity 10000000 -}}
{{- else -}}
{{ . }}
{{- end -}}
{{- end -}}
Note that there are many suffixes besides m and you might want to handle those too, maybe using a dictionary structure. I'm using the Sprig floating-point math functions which should be included in Helm. This template is actual code and you also want to arrange things like tests for it, which Helm does not support well.
Once you have that, gt (greater-than) is a function that takes two parameters. You want to test both "is it present" and also "is it at least this minimum", so you'd have to repeat the value. For a long value like this one thing that can help is to use the standard template with operator, which both acts like an if instruction and also temporarily rebinds the . variable to the value you're testing.
So you could write something like
{{- with .Values.resources.requests.cpu -}}
{{- $quantity := include "resource-quantity" . | float64 }}
{{- if and . (gt $quantity 5.0) }}
cpu: {{ . }}
{{- else }}{{/* if */}}
cpu: 5000m
{{- end }}{{/* if */}}
{{- else }}{{/* with */}}
cpu: 5000m
{{- end }}{{/* with */}}
But with already tests if the value is non-empty, and you can use the maxf function to enforce a minimum value. So (given a complete working tested resource-quantity template function) you could write:
resources:
requests:
{{- with .Values.resources.requests.cpu }}
cpu: {{ include "resource-quantity" . | float64 | maxf 5.0 }}
{{- else }}
cpu: 5.0
{{- end }}
This is how I managed to compare. Below is the example of one of the unit m
{{- if eq $limit_suffix "m" }}
cpu: {{ mulf $limit_value 3 | max 5000 }}{{$limit_suffix}}
{{- else }}
cpu: {{ mulf $limit_value 3 | max 5 }}
{{- end }}
Getting unnicode error when print in html Flask.
Here is my code.
{% if(backpaths) %}
{% for n in backpaths:%}
{% print '%s'%n %}
</br>
{% endfor %}
{% endif %}
I tried to use n.decode('utf-8') but it didn't work and got same error
backpaths is set to:
['1\xe6\x9c\x89 --(HYPER)--> quantifier={indefinite|\xe4\xb8\x8d\xe5\xae\x9a\xe6\x8c\x87} --(HYPO)--> \xe6\x9c\x89 ', '2\xe6\x9c\x89 --(HYPER)--> exist|\xe5\xad\x98\xe5\x9c\xa8 --(HYPO)--> \xe6\x9c\x89 ']
here is the traceback
(most recent call last):
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/ganchimeg/FlaskApp/FlaskApp/__init__.py", line 125, in homepage
return render_template('index.html', backpaths=successPaths)
File "/usr/local/lib/python2.7/dist-packages/flask/templating.py", line 128, in render_template
context, ctx.app)
File "/usr/local/lib/python2.7/dist-packages/flask/templating.py", line 110, in _render
rv = template.render(context)
File "/usr/local/lib/python2.7/dist-packages/jinja2/environment.py", line 969, in render
return self.environment.handle_exception(exc_info, True)
File "/usr/local/lib/python2.7/dist-packages/jinja2/environment.py", line 742, in handle_exception
reraise(exc_type, exc_value, tb)
File "/home/ganchimeg/FlaskApp/FlaskApp/templates/index.html", line 31, in top-level template code
{{ n }}
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe6 in position 16: ordinal not in range(128)
You don't have Unicode strings, you have byte strings. Python tries to implicitly decode those using the standard ASCII codec. Explicitly decode them:
{% if(backpaths) %}
{% for n in backpaths:%}
{{ n.decode('utf8') }}
</br>
{% endfor %}
{% endif %}
It'll be better if you passed in backpaths into the template ready-decoded.
I have two ipynb files in two folders. Once converts no problem, the other wont convert. Am I doing something wrong? I am converting to html
File 1:
cd C:\Users\rcreedon\Dropbox\GIZSupervisor\DATA\Production_Data\STP_Data\Data_Sets\Wave1\1004
ipython nbconvert 1004ProdData.ipynb --to html
A total success
File 2:
cd C:\Users\rcreedon\Dropbox\GIZSupervisor\DATA\Production_Data\STP_Data\Data_Sets\Wave1\1006
ipython nbconvert 1006prodData.ipynb --to html
A Horrid failure.
Error message looks like this
C:\Users\rcreedon\Dropbox\GIZSupervisor\DATA\Production_Data\STP_Data\Data_Sets
Wave1\1006>ipython nbconvert 1006ProdData.ipynb --to html
[NbConvertApp] Using existing profile dir: u'C:\Users\rcreedon\.ipython\pro
ile_default'
[NbConvertApp] Converting notebook 1006ProdData.ipynb to html
[NbConvertApp] Support files will be in 1006ProdData_files\
[NbConvertApp] Loaded template html_full.tpl
[NbConvertApp] ERROR | Error while converting '1006ProdData.ipynb'
Traceback (most recent call last):
File "C:\Anaconda\lib\site-packages\IPython\nbconvert\nbconvertapp.py", line
00, in convert_notebooks
output, resources = exporter.from_filename(notebook_filename, resources=res
urces)
File "C:\Anaconda\lib\site-packages\IPython\nbconvert\exporters\exporter.py",
line 289, in from_filename
return self.from_notebook_node(nbformat.read(f, 'json'), resources=resource
,**kw)
File "C:\Anaconda\lib\site-packages\IPython\nbconvert\exporters\exporter.py",
line 260, in from_notebook_node
output = self.template.render(nb=nb_copy, resources=resources)
File "C:\Anaconda\lib\site-packages\jinja2\environment.py", line 969, in rend
r
return self.environment.handle_exception(exc_info, True)
File "C:\Anaconda\lib\site-packages\jinja2\environment.py", line 742, in hand
e_exception
reraise(exc_type, exc_value, tb)
File "C:\Anaconda\lib\site-packages\IPython\nbconvert\exporters..\templates\
tml_full.tpl", line 1, in top-level template code
{%- extends 'html_basic.tpl' -%}
File "C:\Anaconda\lib\site-packages\IPython\nbconvert\exporters..\templates\
tml_basic.tpl", line 1, in top-level template code
{%- extends 'display_priority.tpl' -%}
File "C:\Anaconda\lib\site-packages\IPython\nbconvert\exporters..\templates\
keleton\display_priority.tpl", line 1, in top-level template code
{%- extends 'null.tpl' -%}
File "C:\Anaconda\lib\site-packages\IPython\nbconvert\exporters..\templates\
keleton\null.tpl", line 26, in top-level template code
{%- block body -%}
File "C:\Anaconda\lib\site-packages\IPython\nbconvert\exporters..\templates\
tml_full.tpl", line 62, in block "body"
{{ super() }}
File "C:\Anaconda\lib\site-packages\IPython\nbconvert\exporters..\templates\
keleton\null.tpl", line 29, in block "body"
{%- block any_cell scoped -%}
File "C:\Anaconda\lib\site-packages\IPython\nbconvert\exporters..\templates\
keleton\null.tpl", line 76, in block "any_cell"
{%- block headingcell scoped-%}
File "C:\Anaconda\lib\site-packages\IPython\nbconvert\exporters..\templates\
tml_basic.tpl", line 64, in block "headingcell"
{{ ("#" * cell.level + cell.source) | replace('\n', ' ') | strip_math_space
| markdown2html | strip_files_prefix | add_anchor }}
File "C:\Anaconda\lib\site-packages\IPython\nbconvert\filters\markdown.py", l
ne 55, in markdown2html
return pandoc(source, 'markdown', 'html', extra_args=['--mathjax'])
File "C:\Anaconda\lib\site-packages\IPython\nbconvert\utils\pandoc.py", line
4, in pandoc
"http://johnmacfarlane.net/pandoc/installing.html"
PandocMissing: The command 'pandoc -f markdown -t html --mathjax' returned an e
ror: [Error 2] The system cannot find the file specified.
Please check that pandoc is installed:
http://johnmacfarlane.net/pandoc/installing.html
not sure if this is still active or not, but a very similar problem was solved for me by adding the cabal binary path (ex $HOME/.cabal/bin) to bash $PATH.
In Jekyll, I would really like to have the date format as "2nd December 2012" — i.e. with the ordinal, rather than just "2 December 2012".
I see that there's an ordinalize function available in Ruby to do this, but I haven't had any luck combining it with Liquid and Jekyll.
How can I format dates as I would like?
I solved this by writing the following Jekyll plugin, which I placed in the _plugins directory with an arbitrary name, e.g. date.rb:
require 'date'
require 'facets/integer/ordinal'
module Jekyll
module DateFilter
def pretty(date)
"#{date.strftime('%e').to_i.ordinalize} #{date.strftime('%B')} #{date.strftime('%Y')}"
end
end
end
Liquid::Template.register_filter(Jekyll::DateFilter)
Then — having installed the facets Ruby gem — I was able to use {{ post.date | pretty }} in my site, and all was well.
In Jekyll 3.8 or higher (for example with GitHub pages) you can just use the new date_to_string filter options and just write:
{{ page.date | date: "%I:%M %p on %A" }}
{{ page.date | date_to_string: "ordinal" }}
This will output: 12:23 PM on Friday 16th Jan 2015
For people using GitHub Pages:
If you're hosting your site on GitHub you won't be able to use modules (I believe GitHub run jekyll build with the --safe option which excludes modules), which means if you were to use Christopher's answer you'd have to build your site locally and then push the contents of the _site dir to GitHub.
Here's a solution to get an ordinal number/date just using Liquid which will allow you to use GitHub Pages + Jekyll in the usual way:
{% capture day %}{{ page.date | date: "%-d" }}{% endcapture %}
{% capture dayLastTwoDigits %}{{ day | modulo: 100 }}{% endcapture %}
{% if dayLastTwoDigits >= "11" and dayLastTwoDigits <= "13" %}
{% assign ordinal = "th" %}
{% else %}
{% capture dayLastDigit %}{{ day | modulo: 10 }}{% endcapture %}
{% case dayLastDigit %}
{% when "1" %}
{% assign ordinal = "st" %}
{% when "2" %}
{% assign ordinal = "nd" %}
{% when "3" %}
{% assign ordinal = "rd" %}
{% else %}
{% assign ordinal = "th" %}
{% endcase %}
{% endif %}
{% capture ordinalDay %}{{ day | append: ordinal }}{% endcapture %}
<p class="post-meta">{{ page.date | date: "%I:%M %p on %A" }} {{ ordinalDay }} {{ page.date | date: "of %b, %Y" }}{% if page.author %} • {{ page.author }}{% endif %}{% if page.meta %} • {{ page.meta }}{% endif %}</p>
This will output something like:
12:23 PM on Friday 16th of Jan, 2015
If you want an entirely Liquid answer, you can do the following:
Create an include file, say for example: ordinalsuffix.html
Put the following code into that file:
{% assign numbertoordinal = (numbertoordinal | default: 0) | plus: 0 | modulo: 100 %}
{% assign ordinalresult = "th" %}
{% case numbertoordinal %}
{% when 1 or 21 or 31 or 41 or 51 or 61 or 71 or 81 or 91 %}
{% assign ordinalresult = "st" %}
{% when 2 or 22 or 32 or 42 or 52 or 62 or 72 or 82 or 92 %}
{% assign ordinalresult = "nd" %}
{% when 3 or 23 or 33 or 43 or 53 or 63 or 73 or 83 or 93 %}
{% assign ordinalresult = "rd" %}
{% endcase %}
Then you can essentially call it like a function, like such:
{% assign numbertoordinal = 101 %}
{% include ordinalsuffix.html %}
{% assign result = numbertoordinal | append: ordinalresult %}
Of course, you'll need to expand this for it to output fully formatted dates. But if you want to know what ordinal suffix any arbitrary number has, this is a reasonably clean answer.
Cant get the CUR status working. the menue always have the classes marked with 0 instead of those marked with 2. what i am doing wrong? My typoscript code:
10.marks {
MENU_OBEN = HMENU
MENU_OBEN {
special = directory
special.value = 10
1 = TMENU
1 {
wrap = <ul>|</ul>
noBlur = 1
NO = 1
NO {
allWrap = <li class="first0"> | </li> |*| <li class="normal0"> | </li> |*| <li class="last0"> | </li>
stdWrap.wrap = <strong> | </strong> |*| | |*| <b> | </b>
}
CUR = 1
CUR {
allWrap = <li class="first2"> | </li> |*| <li class="normal2"> | </li> |*| <li class="last2"> | </li>
stdWrap.wrap = <strong> | </strong> |*| | |*| <b> | </b>
}
}
}
Don't see anything obvious, but have you tried removing the NO = 1 line? IIRC the normal ("NO") state doesn't need to be explicitly set, as long as you set some properties for it... maybe by setting it explicitly you're overriding the state?
In my general ts template I have no NO=1. Instead I copy the NO status into CUR. I really dont know why, but it works for me this way.
e.g.
NO.wrapItemAndSub = <li> | </li>
NO.stdWrap.htmlSpecialChars = 1
CUR < .NO
CUR = 1
CUR.ATagParams = class="cur"
ACT < .NO
ACT = 1
ACT.ATagParams = class="act"
Keep in mind that for page shortcuts this cannot work, since if you klick on a shortcut you never are on the page which is supposed to become active/current.
Just change the page property to standard page and set "Display Content of Page" in "Apperance" Tab.