Paths with assemble and swig - path

i have a project running grunt with assemble and swig as the engine for templating. i need to know how to handle paths for my navigation, because i want to store some files in subfolders.
i just found this for assemble: http://assemble.io/helpers/helpers-path.html
but that doesn't work for me, it says "Warning: Unexpected string Use".
anyone knows a solution for that? do you need any further information?

Thanks for your help at first! I found a first solution myself today:
{{ _dirname(page) }} doesn't work either, because dirnameis related to the layout file where I created my navigation. It does work if I use page.dirname.
My code now looks like
<ul class="navigation-level-1">
<li class="item-level-1 {% if basename == "page" %}current{% endif %}">
<a href="{% if dirname != 'root' %}../{% endif %}page.html" class="text-level-1">
Guild
</a>
<ul class="navigation-level-2">
<li class="item-level-2">
subpage
</li>
</ul>
</li>
</ul>
But the Problem with this is, that I cannot get into subpages from other pages if i entered one subpage. I hope someone can understand what i mean :D
I try to visualize:
* Page A
** Subpage A
* Page B
** Subpage B
If I entered Subpage A and I want to visit Subpage B i can't do so because my solution just works if I am on the root, you know?
Any ideas? :)

Related

SnipCart site: "$localize" showing up in Google search result snippet

I have customized my SnipCart e-commerce site following the customization documentation:
<div hidden id="snipcart" data-api-key="MY_KEY">
<address-fields>
<div>
<div class="snipcart-form__row">
<div class="snipcart-form__field snipcart-form__cell--large">
<snipcart-label class="snipcart__font--tiny" for="address1">
{{ $localize('address_form.address1') }}
</snipcart-label>
However, now I see $localize showing up in Google search results instead of the English text.
Google Search Console shows that the SnipCart .js resource (.css too) is blocked because of cdn.snipcart.com/robots.txt (which is configured to not allow crawling of anything). This seems to be the problem.
What is the proper way to fix this?
Answering my own question in case someone else stumbles into this.
You can prevent certain content from showing up in the snippet with the data no-snippet directive, for example:
<span data-nosnippet>Don't show me</span>
Reference:
https://developers.google.com/search/docs/advanced/crawling/special-tags#data-nosnippet

Hyperlink not clickable on Internet Explorer if use Url.Action

I used the mvc actionlink to get the url. It is working fine in chrome. But in IE it is not even clicking. i used the following code to navigate the page.
<a href="#Url.Action("GetHelpDocuments", "Document")">
<span class="navsprite helplink"></span>
<span>Help</span>
I don't find any error in my above code. But please give alternate solution for this.
I used localtion.href to get the actual location href
<a href="#Url.Action("GetHelpDocuments", "Document")" onclick='location.href = this.getAttribute("href")'>
<span class="navsprite helplink" ></span>
<span>Help</span>

Nokogiri results different from brower inspect

I am trying to scrape a site but the results returned for just the links is different from when I inspect it with the browser.
In my browser I get normal links but all the a HREF links all become javascript:void(0); from Nokogiri.
Here is the site:
https://www.ctgoodjobs.hk/jobs/part-time
Here is my code:
url = "https://www.ctgoodjobs.hk/jobs/part-time"
response = open(url) rescue nil
next unless response
doc = Nokogiri::HTML(open(url))
links = doc.search('.job-title > a').text
is not that easy, urls are "obscured" using a js function, that's why you're getting javascript: void(0) when asking for the hrefs... looking at the html, there are some hidden inputs for each link, and, there is a preview url that you can use to build the job preview url (if that's what you're looking for), so you have this:
<div class="result-list-job current-view">
<input type="hidden" name="job_id" value="04375145">
<input type="hidden" name="each_job_title_url" value="barista-senior-barista-咖啡調配員">
<h2 class="job-title">Barista/ Senior Barista 咖 啡 調 配 員</h2>
<h3 class="job-company">PACIFIC COFFEE CO. LTD.</h3>
<div class="job-description">
<ul class="job-desc-list clearfix">
<li class="job-desc-loc job-desc-small-icon">-</li>
<li class="job-desc-work-exp">0-1 yr(s)</li>
<li class="job-desc-salary job-desc-small-icon">-</li>
<li class="job-desc-post-date">09/11/16</li>
</ul>
</div>
<a class="job-save-btn" title="save this job" style="display: inline;"> </a>
<div class="job-batch-apply"><span class="checkbox" style="background-position: 0px 0px;"></span><input type="checkbox" class="styled" name="job_checkbox" value="04375145"></div>
<div class="job-cat job-cat-de"></div>
</div>
then, you can retrieve each job_id from those inputs, like:
inputs = doc.search('//input[#name="job_id"]')
and then build the urls (i found the base url at joblist_preview.js:
urls = inputs.map do |input|
"https://www.ctgoodjobs.hk/english/jobdetails/details.asp?m_jobid=#{input['value']}&joblistmode=previewlist&ga_channel=ct"
end
Take the output of a browser and that of a tool like wget, curl or nokogiri and you will find the HTML the browser presents can differ drastically from the raw HTML.
Browsers these days can process DHTML, Nokogiri doesn't. You can only retrieve the raw HTML using something that lets you see the content without the browser, like the above mentioned tools, then compare that with what you see in a text editor, or what nokogiri shows you. Don't trust the browser - they're known to lie because they want to make you happy.
Here's a quick glimpse into what the raw HTML contains, generated using:
$ nokogiri "https://www.ctgoodjobs.hk/jobs/part-time"
Nokogiri dropped me into IRB:
Your document is stored in #doc...
Welcome to NOKOGIRI. You are using ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin15]. Have fun ;)
Counting the hits found by the selector returns:
>> #doc.search('.job-title > a').size
30
Displaying the text found shows:
>> #doc.search('.job-title > a').map(&:text)
[
[ 0] "嬰 兒 奶 粉 沖 調 機 - 兼 職 產 品 推 廣 員 Part Time Promoter (時 薪 高 達 HK$90, 另 設 銷 售 佣 金 )",
...
[29] "Customer Services Representative (Part-time)"
]
Looking at the actual href:
>> #doc.search('.job-title > a').map{ |n| n['href'] }
[
[ 0] "javascript:void(0);",
...
[29] "javascript:void(0);"
]
You can tell the HTML doesn't contain anything but what Nokogiri is telling you, so the browser is post-processing the HTML, processing the DHTML and modifying the page you see if you use something to look at the HTML. So, the short fix is, don't trust the browser if you want to know what the server sends to you.
This is why scraping isn't very reliable and you should use an API if at all possible. If you can't, then you're going to have to roll up your sleeves and dig into the JavaScript and manually interpret what it's doing, then retrieve the data and parse it into something useful.
Your code can be cleaned up and simplified. I'd write it much more simply as:
url = "https://www.ctgoodjobs.hk/jobs/part-time"
doc = Nokogiri::HTML(open(url))
links = doc.search('.job-title > a').map(&:text)
The use of search(...).text is a big mistake. text, when applied to a NodeSet, will concatenate the text of each contained node, making it extremely difficult to retrieve the individual text. Consider this:
require 'nokogiri'
doc = Nokogiri::HTML(<<EOT)
<html>
<body>
<p>foo</p>
<p>bar</p>
</body>
</html>
EOT
doc.search('p').class # => Nokogiri::XML::NodeSet
doc.search('p').text # => "foobar"
doc.search('p').map(&:text) # => ["foo", "bar"]
The first result foobar would require being split apart to be useful, and unless you have special knowledge of the content, trying to figure out how to do it will be a major pain.
Instead, use map to iterate through the elements and apply &:text to each one, returning an array of each element's text.
See "How to avoid joining all text from Nodes when scraping" and "Taking apart a DHTML page" also.

PHP include outside url

When trying to include a php file into another it either does nothing at all (no errors). If i require it will give a useless message
"Failed opening required 'http://example.org.com/xxx.php' (include_path='.:/usr/local/php5/lib/php')
<div id="menu"> <?php include("http://www.sitename.com/menu.php") ?> </div>
The file im trying to include is on the same site and host.
The page im including from is:
root/wiki/skin/index.php (mediawiki)
menu.php is located:
root/menu.php
since mediawiki treats the /wiki/ path as the root i cannot back out with ../../ etc.
What am i doing wrong here? Thanks
Sir, try this:
<div id="menu"> <?php include("../../menu.php") ?> </div>
To include URLs in your PHP project you must have enabled (true) this option:
allow_url_include
in your php.ini configuration. More information you can find here:
http://php.net/manual/en/filesystem.configuration.php#ini.allow-url-include

Textmate with HTML(rails) Problem

I am editing a .html.erb file with HTML(rails) selected at the bottom. When I type if I get:
< ?php if (condition): ? >
< ?php endif ? >
Any ideas?
Cheers
Don't fully understand but when I type:
if and hit TAB, I get PHP instead:
<?php if (condition): ?>
<?php endif ?>
You could create your own ERB snippet for example on IF, TAB:
<% if ${1:value?} %>
${2}
<% end %>
Suggestion: Open your Bundle Editor and delete the PHP bundle in you don't need it. This way, I won't interfere with your ERB templates again.
You probably have an incorrect manual binding for .erb files. To see what manual bindings you have run
defaults read com.macromates.textmate OakLanguageFileBindings
If you want to get rid of all your manual bindings, quit TextMate and run
defaults delete com.macromates.textmate OakLanguageFileBindings
More info here http://blog.macromates.com/2007/file-type-detection-rspec-rails/

Resources