Replace .Page.UniqueID in hugo to resolve deprecation warning - hugo

I'm using the blogdown theme:
https://github.com/shawnohare/hugo-tufte
I've fixed most of the build warnings I get, but I'm having trouble resolving this one:
Page.UniqueID is deprecated and will be removed in a future release. Use .File.UniqueID
I've tracked down the instance of Page.UniqueID to a couple of files which are used to create margin notes via a shortcode.
{{ $marginnoteDomIdSuffix := .Ordinal }}<label for="marginnote-{{ .Page.UniqueID}}-{{ $marginnoteDomIdSuffix }}" class="margin-toggle">⊕</label>
<input type="checkbox" id="marginnote-{{ .Page.UniqueID}}-{{ $marginnoteDomIdSuffix }}" class="margin-toggle"/>
<span class="marginnote">{{ .Inner }}</span>
I've tried a number of replacements of the .File.UniqueID type (.File.UniqueID, .UniqueID, ..File.UniqueId, you get the idea) as suggested in the warning, but have not had much success.

Related

Where does imageConfig (HUGO) look for images when building the site?

I'm trying to get the size (width and height) of an image located inside my static folder
I wrote:
{{$imagelink := print "/static" (.Params.image | relURL) }}
{{$imgData := imageConfig $imagelink }}
<p>{{ $imgData.Height }}</p>
<p>{{ $imgData.Width }}</p>
where .Params.image is taken from the YAML metadata, e.g.: image: "images/my-image.PNG" of each post.
The previous works well if I save the file when the server is running. I can get the width and the height, but if I build my site with build_site(local = TRUE) (I'm using blogdown) HUGO can't find the images.
I tried debugging the error with {{ errorf "Specified file at %s not found." $imagelink }}, but whatever path I try it never founds the images.
I also followed this tutorial about imageConfig, where they point out the following:
but {{$imagelink := print "/static/static" (.Params.image | relURL) }} doesn't work either.
I haven't found official documentation regarding this issue. Any help is appreciated.
This issue was solved upgrading HUGO and blogdown to the latest version

AngularJS: Error while interpolating: {{ $index + 1 }}

I used $index inside simple ng-repeat to show items' number:
<li ng-repeat="item in dataList | limitTo:5">
<span>{{ $index + 1 }} </span>
</li>
And it worked OK for long time.
But sudden couple days ago I started getting:
Error: Error while interpolating: {{ $index + 1 }} illegal access
at Error (native)
at Object.k (/vendors/angular/angular.min.js:55:287)
at Object.e.$digest (/vendors/angular/angular.min.js:90:233)
at Object.e.$apply (/vendors/angular/angular.min.js:92:431)
at Object.<anonymous> (/js/controllers/HomePage.js:99:28)
at l (/vendors/jquery/jquery.min.js:4:24797)
at Object.c.fireWith [as resolveWith] (/vendors/jquery/jquery.min.js:4:25618)
at k (/vendors/jquery/jquery.min.js:6:5201)
at XMLHttpRequest.<anonymous> (/vendors/jquery/jquery.min.js:6:9005)
at both production and local environments.
Data in dataList is correct and the same as was all time previous.
It is reproducible only in latest Chrome (32.0.1700.14) in other browsers it still working correct.
Any ideas why this can happen and how it can be fixed?
Angular version: 1.1.5.
Debugging showed that exception is thrown from angular.js:6371 on native adding operation, and it is not about AngularJS itself.
For those who are getting same issue, looks like the only solution is to find any alternative way of implementing your task on which it is failing. At least till next Google Chrome update.
Thanks to #Heikki for pointing to chromium issues tracker.
Since the bug is related to String + Number concatenation I am using toString() on the numbers as a temp workaround.
{{($index + 1).toString()}}
worked in my case.

postLink generates invalid code at CakePHP 2.3

I am using CakePHP 2.3
I have two environments where I have my web application. At the testing environment with the exact same version of the application (all files are the same) I am having a problem with the Form->postLink method.
It shows this error on the Javascript console:
Uncaught TypeError: Object # has no method 'submit' users:119
onclick
Comparing the resulting HTML from both environments I can notice that the attributes name and id generated by this method are repeated more than once in the same page (which shouldn't be like that).
This is the code use to generate those post links:
foreach($users as $user){
$delete = $this->Form->postLink(__('Delete'), array('action' => 'delete', $user['user_id']), __('Are you sure you want to delete %s?', $user['user_id']));
}
This is the problematic generated HTML with repeated values for id and name as you can see:
<!-- link 1 -->
<form action="delete/1/" name="post_51e8019d095f1" id="post_51e8019d095f1" style="display:none;" method="post">
<input type="hidden" name="_method" value="POST"/>
</form>
Delete
<!-- link 2 -->
<form action="delete/2/" name="post_51e8019d095f1" id="post_51e8019d095f1" style="display:none;" method="post">
<input type="hidden" name="_method" value="POST"/>
</form>
Delete
Why is this happening?
Could it be related with the configuration of the web server somehow? I don't see another explanation for it...
Thanks.
The problem was caused by a bug in IIS 7.0.6000.16386 and the PHP function uniqid as pointed out here.
I am using a slightly different version in both environments ( IIS 7.0.6000.16386 vs IIS 7.5.7600.16385) and that was the cause of the problem.
In order to solve it I modified the file lib/Cake/View/Helper/FormHelper.php chaning the line $formName = uniqid('post_'); inside the postLink function to:
$formName = uniqid('post_', true);
That adds more entropy and as the documentation says:
If set to TRUE, uniqid() will add additional entropy (using the combined linear congruential generator) at the end of the return value, which increases the likelihood that the result will be unique.
Update
Ended up having to add one more change due to problems with javascript in forms.
I added one more line after $formName = uniqid('post_', true); so it looks like:
$formName = uniqid('post_', true);
$formName = str_replace('.', '', $formName);

In jinja2 on Google App Engine, how can I (easily) build a URL based on a route name with arguments?

If I construct a jinja environment as follows:
jinja_environment = jinja2.Environment (
loader=jinja2.FileSystemLoader ((os.path.dirname (__file__), 'templates')), extensions=[])
jinja_environment.globals['url_for'] = webapp2.uri_for
In my templates, I can build simple URLs from a route name when the route does not define any arguments:
{{ url_for('user_home') }}
However, when the route contains an argument as defined by a string such as /invoice/<:\d+>, I am unable to pass any arguments. Calling it in all the following ways fails, with a KeyError "Missing argument "0" to build URI.":
{{ url_for('invoice') }}
{{ url_for('invoice', args=['123']) }}
{{ url_for('invoice', kwargs={'__0__':'123'}) }}
{{ url_for('invoice',_request=None, args=['123'],kwargs={'__0__':'123'}) }}
Existing examples for this seem to be out of date--at least I haven't been able to make them work. What am I missing?
Route('/invoice/<invoice_id>/', handler=invoice_handler, invoice_id='something')
{{ url_for('invoice', invoice_id=123) }}
You can try the above, Jinja is expecting the named parameter you defined your handler.
I think just {{ url_for('invoice', 123) }} should work.

angularjs + yeoman + ng-switch + build:minify -> assertion

I am using an ng-switch in angularjs to have dynamic content in my page, dependent on the url. And I am managing my project with yeoman. Here is the code of the dynamic content generation:
html:
<div class="div-content bgcontent" id="content">
<span ng-switch on="renderPath[0]">
<div ng-switch-when="home" ng-include="'partials/home.html'"></div>
<div ng-switch-when="gallery" ng-include="'partials/gallery.html'"></div>
</span>
</div>
controller:
$scope.renderPath = $location.path().split('/');
// remove first entry because it's empty string
$scope.renderPath.shift();
This works perfectly well when running the stuff with 'yeoman server'. But if I build with 'yeoman build:minify', it doesn't work anymore afterwards. It hits an assertion:
at assertArg (http://host:8888/scripts/vendor/d10639ae.angular.js:973:11)
at Object.ngDirective.compile (http://host:8888/scripts/vendor/d10639ae.angular.js:13474:5)
at applyDirectivesToNode (http://host:8888/scripts/vendor/d10639ae.angular.js:4047:32)
at compileNodes (http://host:8888/scripts/vendor/d10639ae.angular.js:3794:14)
at compileNodes (http://host:8888/scripts/vendor/d10639ae.angular.js:3799:14)
at compile (http://host:8888/scripts/vendor/d10639ae.angular.js:3739:29)
at update (http://host:8888/scripts/vendor/d10639ae.angular.js:13685:22)
at $get.Scope.$broadcast.next (http://host:8888/scripts/vendor/d10639ae.angular.js:8002:24)
at Array.forEach (native)
at forEach (http://host:8888/scripts/vendor/d10639ae.angular.js:110:11) <!-- ngSwitchWhen: home -->
Does someone know how to fix this? Or where I need to look to debug it?
If you are using dependency-injection within your scripts, make sure to use the minify-proof syntax as described here: http://docs.angularjs.org/guide/di

Resources