Hugo syntax highlighting not changing - syntax-highlighting

I am using Hugo v0.58.3 with Chroma highlighting.
I have read the instructions about using this command hugo gen chromastyles --style=vs > syntax.css to download the style sheet I want. I use it to overwrite the theme/sometheme/static/css/syntax.css
I have tried a few different styles but changing them seem to have no impact.
I have added two parameters to the config.toml
pygmentsCodeFences = true
pygmentsUseClasses = true
My source code is highlighted like this -
{{< highlight csharp >}}
public void ConfigureServices(IServiceCollection services)
{
services.//snip
{{< /highlight >}}
No matter what syntax.css I download, no change occurs on the page.
What am I doing wrong? Is there an example someone can point me to that shows this working.

For the benefit of anyone else who finds this post, here is the problem I was having.
I was using the "Beautiful Hugo" theme with their example app.
In the config.toml I had -
pygmentsCodeFences = true
pygmentsUseClasses = true
But the example config.toml also had -
useHLJS = true
The head.html had -
{{- if .Site.Params.useHLJS }}
<link rel="stylesheet" href="{{ "css/highlight.min.css" | absURL }}" />
{{- else -}}
<link rel="stylesheet" href="{{ "css/syntax.css" | absURL }}" />
{{- end -}}
loading the highlight.min.css instead of syntax.min.

Related

How To Add Title For Each Page In Laravel

In my laravel website all pages having same title meta but how to make different title for each page please tell me.
this is my code for dynamic showing in all the pages
<title>{{setting('site.title')}} | {{setting('site.description')}} #if(isset($data->title)) {{$data->title}} #endif</title>
file name is layouts/app.blade.php
Inside your app.blade.php, in the head section.
change:
<title>{{ config('app.name', 'Laravel') }}</title>
to:
<title>#yield('title')</title>
You can choose any name/title that seems fitting.
For other views.blade.php pages,(extending app.blade.php) you can add a title this way:
#section('title','My Title')
this comes after #extends('layouts.app')
You can specify different title for different views.
In you common header file make your title like this:
<title>#yield('page_title', 'Default Title')</title>
Then in your view file change the title to whatever you want it to be set in following way:
#section('page_title')
{{ "Your Title" }}
#endsection
Simply inside your app.blade.php
Put this: #yield('title')
In other pages just extend the layout and put the new title at the this section
#extends('layoutWhateverYouNamedIt')
#section('title')
Type your title here
#endsection
in your controller
public function aboutUs()
{
//page title
$title = 'Project | About Us';
return view('project.about_us', compact('title'));
}
for your view page
<title>{{ $title }}</title>
Inside your app.blade.php,
<head>
#yield('title')
... // other scripts
</head>
For other pages which user app.blade.php you can use it like after extending app.blade.php :
#section('title')
<title> Your Page Title Here </title>
#endsection`
Hope it helps. happy coding.

Working with merged js and css in Laravel 5.3

I am following this: https://laravel.com/docs/5.3/elixir
Here is my gulpfile.js:
elixir(mix => {
mix.webpack('app.js')
.styles([
'bootstrap.min.css',
'agency.css',
'font-awesome.min.css',
'bootstrap-social.css',
'bootstrap-datetimepicker.min.css',
'select2.min.css',
'icheck.css',
'custom.css'
])
.scripts([
'jquery.easing.min.js',
'jqBootstrapValidation.js',
'agency.min.js',
'moment.js',
'bootstrap-datetimepicker.min.js',
'select2.min.js',
'contact_me.js',
'icheck.min.js',
'ckeditor.js',
'echo.js',
'custom.js'
])
.version(['css/all.css', 'js/all.js']);
});
Here, I'm simply merging all css and js files into two files: all.css and all.js to minimise HTTP request(to improve performance)
Those two merged files, getting stored at
public/build/css/all-5ba9458ba4.css
public/build/js/all-1723826a20.js
And I'm including them into templates like:
<link rel="stylesheet" href="{{ elixir('css/all.css') }}">
<script src="{{ elixir('js/all.js') }}"></script>
The issue here is that those combined css and js i.e all.css and all.js getting stored inside of "build" directory.
So, I need to move other related dependencies (like fonts) inside that build directory.
So, what is the solution over here?
Any help would be appreciated.
Thanks,
Parth vora
Elixir's version method allows you to set a path I believe
mix.version(['css/all.css', 'js/all.js'], 'public');
Then use
elixir('path/to/script.js', null) // note the null
In your case
<link rel="stylesheet" href="{{ elixir('css/all.css', null) }}">
<script src="{{ elixir('js/all.js', null) }}"></script>
This should work:
mix.version(['style.css', 'script.js'], 'public');
https://laravel.com/docs/5.3/elixir#versioning-and-cache-busting
As per this documetation, I think there is no such option to provide custom path for version method.
https://laravel.com/docs/5.3/elixir#versioning-and-cache-busting

Parameter in Route::get caused style to disappear?

I'm still new to Laravel. Anyway, I'm making a small system of viewing and creating articles to be shown in the main site. I wanted to create a page that displays an article from the database, using a parameter from the URL, like this:
http://localhost:8000/read/1
The above, for example, will display the article with 'id' value of 1 in the database.
So it works just fine, but problem is, after I got it to work (which took me some time since I'm a newbie), the whole style just disappears from the page. I tried to rewrite everything but it still didn't work. New pages that I create include the style just fine.
This is my route line:
Route::get('read/{id}', array('as' => 'read', 'uses' => 'NewsController#readArticle'));
NewsController readArticle function:
public function readArticle($id) {
$article = NewsMessage::where('id', $id) -> first();
return View::make('news.read', array('article' => $article));
}
And the file read.blade.php (located in views/news/read.blade.php)
#extends('layouts.main')
#section('content')
{{ $article -> title }}
#stop
So the whole PHP code works fine and I manage to get the title. But for some reason, the whole style disappears and this is what I see:
http://puu.sh/ctO6J/db30fbe102.png
So any idea, what have I dont wrong that caused this? The other pages work just fine with the style included.
Thank you!
The issue is that the path to the image is incorrectly specified.
You can either use the built in asset methods or something like {{ URL::to('/')/imagepathhere/filename.jpg }}
Assuming you have your styles links wrote as:
#extends('layouts.main')
#section('styles')
<link href="css/custom.css" rel="stylesheet" />
<link href="css/styles.css" rel="stylesheet" />
#endsection
#section('content')
{{ $article -> title }}
#endsection
Correct Syntax:
#extends('layouts.main')
#section('styles')
<link href="{{ asset('css/custom.css') }}" rel="stylesheet" />
<link href="{{ asset('css/styles.css') }}" rel="stylesheet" />
#endsection
#section('content')
{{ $article -> title }}
#endsection
And make sure your css folder is located at public folder when calling with asset() helper.
This issues of disappearing the whole page styles is causing by accessing the image or css file or any other resources, and the solution is to use asset() helper function.
NOTE: YOUR ROUTES AND CONTROLLER HAS NO ISSUE, YOU DON'T NEED TO TOUCH EITHER.

Optimising html/template Composition

I'm looking to see if there is a better (faster, more organised) way to split up my templates in Go. I strongly prefer to stick to html/template (or a wrapper thereof) since I trust its security model.
Right now I use template.ParseGlob to parse all of my template files in within init().
I apply template.Funcs to the resulting templates
I set a $title in each template (i.e. listing_payment.tmpl) and pass this to the content template.
I understand that html/template caches templates in memory once parsed
My handlers only call t.ExecuteTemplate(w, "name.tmpl", map[string]interface{}) and don't do any silly parsing on each request.
I compose templates from multiple pieces (and this is the bit I find clunky) as below:
{{ $title := "Page Title" }}
{{ template "head" $title }}
{{ template "checkout" }}
{{ template "top" }}
{{ template "sidebar_details" . }}
{{ template "sidebar_payments" }}
{{ template "sidebar_bottom" }}
<div class="bordered-content">
...
{{ template "listing_content" . }}
...
</div>
{{ template "footer"}}
{{ template "bottom" }}
My three questions are:
Is this performant, or do the multiple {{ template "name" }} tags result in a potential per-request performance hit? I see a lot of write - broken pipe errors when stress testing heavier pages. This might just be due to socket timeouts (i.e. socket closing before the writer can finish) rather than some kind of per-request composition, though (correct me if otherwise!)
Is there a better way to do this within the constraints of the html/template package? The first example in Django's template docs approaches what I'd like. Extend a base layout and replace the title, sidebar and content blocks as needed.
Somewhat tangential: when template.ExecuteTemplate returns an error during a request, is there an idiomatic way to handle it? If I pass the writer to an error handler I end up with soup on the page (because it just continues writing), but a re-direct doesn't seem like idiomatic HTTP.
With some help on Reddit I managed to work out a fairly sensible (and performant) approach to this that allows:
Building layouts with content blocks
Creating templates that effectively "extend" these layouts
Filling in blocks (scripts, sidebars, etc.) with other templates
base.tmpl
<html>
<head>
{{ template "title" .}}
</head>
<body>
{{ template "scripts" . }}
{{ template "sidebar" . }}
{{ template "content" . }}
<footer>
...
</footer>
</body>
index.tmpl
{{ define "title"}}<title>Index Page</title>{{ end }}
// We must define every block in the base layout.
{{ define "scripts" }} {{ end }}
{{ define "sidebar" }}
// We have a two part sidebar that changes depending on the page
{{ template "sidebar_index" }}
{{ template "sidebar_base" }}
{{ end }}
{{ define "content" }}
{{ template "listings_table" . }}
{{ end }}
... and our Go code, which leverages the map[string]*template.Template approach outlined in this SO answer:
var templates map[string]*template.Template
var ErrTemplateDoesNotExist = errors.New("The template does not exist.")
// Load templates on program initialisation
func init() {
if templates == nil {
templates = make(map[string]*template.Template)
}
templates["index.html"] = template.Must(template.ParseFiles("index.tmpl", "sidebar_index.tmpl", "sidebar_base.tmpl", "listings_table.tmpl", "base.tmpl"))
...
}
// renderTemplate is a wrapper around template.ExecuteTemplate.
func renderTemplate(w http.ResponseWriter, name string, data map[string]interface{}) error {
// Ensure the template exists in the map.
tmpl, ok := templates[name]
if !ok {
return ErrTemplateDoesNotExist
}
w.Header().Set("Content-Type", "text/html; charset=utf-8")
tmpl.ExecuteTemplate(w, "base", data)
return nil
}
From initial benchmarks (using wrk) it seems to be a fair bit more performant when it comes to heavy load, likely due to the fact that we're not passing around a whole ParseGlob worth of templates every request. It also makes authoring the templates themselves a lot simpler.

Implement layout tag for liquid template engine

I want to themed my blog that use liquid template engine, but default, the engine only support some basic tags, I want to write custom tag {% layout 'layout_name' %}
Layout file: dark.liquid
<html>
...
{% content_for_body %}
...
</html>
And template file: blog.liquid
{% layout 'dark' %}
welcome to my blog!
And output
<html>
...
welcome to my blog!
...
</html>
Thanks!
I don't think that something like this is possibly except for grabbing the first line and extracting the layout name before passing the rest of blog.liquid in, for example:
post = "{{ layout 'dark' }}\nWelcome to my blog!"
layout_name = post.split("\n").first.match(/\{\{ layout '(.+)' \}\}/)[1]
#=> "dark"
content = post.split("\n")[1..-1].join("\n")
#=> "Welcome to my blog!"
Also it should be "{{ content_for_body }}"; "{% ... %}" is used for tag blocks like an if statement.

Resources