Jekyll, how to display images in a folder by date? - jekyll

I am creating a website gallery. There is such a structure:
my site
artworks
caty1
caty2
It is necessary to display the photos in page of a given category (caty2 or caty1) by creation date.
Actually, how to realize using Jekyll and Liqiud?
Or is there a more appropriate structure for this?

with liquid you can filter/sort an array but any of its elements attribute that you want.
in your case you need to create datafile (in yml, csv or json) representing a collection of photos, and each photo should have a date attribute (along with a name, src, ...).
then in the layout that generate a caty page you'll have some thing like:
{% assign sorted-photos = site.data.photos | sort: 'date' %}
<ul> <!-- list of sorted photos -->
{% for photo in photos %}
<li> <img src={{photo.src}} alt={{photo.name}}></li>
{% endfor %}
</ul>
the photos collection would be a photos.yml file located in _data directory with a structure similar to:
- src = assets/img/p1.jpg
date = 10-01-2017
name = cute cat
category = cats # if you need to filter by category ?
- src = assets/img/p2.jpg
date = 12-01-2017
name = grumpy cat-2
category = cats
- src = assets/img/p3.jpg
date = 10-11-2016
name = cool dog
category = dogs

Related

How to get readable text from html block

region = input("Insert region of search ").lower()
#Get region of the world for language
first_name , last_name = input("").split()
#Get first and last name of person of interest or object
res = requests.get("https://"+ region + ".wikipedia.org/wiki/" + first_name + "_" + last_name)
#get Wiki page of person/object
soup = BeautifulSoup(res.text, "html.parser")
#Parse in html
infobox = (soup.select("img")[:4])
#Get the first 4 images
content = (soup.select("p")[0])
#Get the first block of text
for info in range(len(infobox)):
link = infobox[info].get("src")
if first_name in link:
urllib.request.urlretrieve("http:" + link, "sample.png")
img = Image.open("sample.png")
img.show()
break
#Loop through images until it finds the one about the person/object
So I made this small program, that basically brings back the picture of what you search for - I'm sure it can be improved, if you have any feedback/tips - but I also want to get the first block of text from the wiki article - I am able to get the block of html text, but I do I remove the <p> and <b> ?
Found it, you just have to put ".text" in the content

Rename hyperlinks in query result in Semantic MediaWiki

Here is my query
{{#ask: [[Category:Pages]]
|mainlabel = Link
|? volume = Volume
|? page = Volume page
|? title = Title
|limit = 3
}}
The result table is like (screenshot)
Link Volume Volume page Title
HPB-SB-1-1 1 1 Article A
HPB-SB-1-10 1 10 Article B
HPB-SB-1-100 1 100 Article C
Where each cell in Link column is actually a hyperlink leading to the corresponding page. What I need to do is somehow rename the cells in Link column to still be hyperlinks but have name of ones from Title column. So the result table become:
Link Volume Volume page
Article A 1 1
Article B 1 10
Article C 1 100
Does anyone knows how can this be achieved with Semantic Mediawiki? Thanks in advance!
You want to use template format:
{|
! Link !! Volume !! Volume page
{{#ask: [[Category:Pages]]
|mainlabel = Link
|? volume = Volume
|? page = Volume page
|? title = Title
|limit = 3
|format = template
|template = table_row
}}
|}
where Template:table_row is:
{{!}}-
{{!}} [{{{1}}}} {{{4}}}] {{!}}{{!}} {{{2}}} {{!}}{{!}} {{{3}}}

How can I add a menu for each content type in hugo

I have the following directory structure for my hugo site:
content/
- posts/
- some_post.md
- talks
- some_talk.md
about.md
I would like the main menu for this site to include entries for posts and talks. Currently I am able to add a menu item for about, by adding menus = main to the front matter, however, I would like the posts and talks links to redirect to indexes of their content, rather than be static pages that I maintain directly. Is this possible?
It turns out that this is possible using the menu configuration in config.toml. The weight attribute is used for ordering the menus:
[menu]
[[menu.main]]
identifier = "home"
name = "home"
url = "/"
weight = 10
[[menu.main]]
identifier = "blog"
name = "blog"
url = "/post/"
weight = 20
[[menu.main]]
identifier = "talks"
name = "talks"
url = "/talks/"
weight = 30
[[menu.main]]
identifier = "about me"
name = "about me"
url = "/about/"
weight = 40

October CMS (Rainlab Blog) - Next and Prev Post link from same category

I have a blog post page where I'm using the category as a hardcoded parameter in url.
The url is like
url = "/category1/:slug"
I'm using blogPost component in this layout.
I can get the nextPost and prevPost link using the following code in template
{% set nextPost = blogPost.post.nextPost %}
{% set prevPost = blogPost.post.previousPost %}
But I want to constraint nextPost and prevPost to be from same category as blogPost.post i.e. category1
blogPost.post belogs to only one category
I've checked that the Post model has a method scopeFilterCategories
but I'm not sure how to use it or if it serves the same purpose.
Code
This is the configuration part
title = "Category1 post"
url = "/category1/:slug"
layout = "default"
is_hidden = 0
robot_index = "index"
robot_follow = "follow"
[blogPost]
slug = "{{ :slug }}"
categoryPage = "category1"
It seems Thye are not Providing that Out of the box
I have created snippets which can do that work.
In you page's code block add this code snippet [ next previous works based on published_at field (Published on in form) ]
public function nextPost($post) {
// get current cats
$postCats = $post->categories->pluck('id')->toArray();
// Here you need to pass it as we are
// hardcoding category slug in URL so we have no data of category
// IF YOU DONT WANT CAT COME FROM POST
// YOU CAN HARD CODE THEM $postCats = ['2']
// here 2 is id of category
// use this cats to scope
$nextPost = $post->isPublished()->applySibling(-1)
->FilterCategories($postCats)->first();
// check if next is not availabe then return false
if(!$nextPost) {
return false;
}
// create page link here same page
$postPage = $this->page->getBaseFileName();
// set URl so we can direct access .url
$nextPost->setUrl($postPage, $this->controller);
// set Cat URl so we can use it directly if needed
$nextPost->categories->each(function($category) {
$category->setUrl($this->categoryPage, $this->controller);
});
return $nextPost;
}
public function previousPost($post) {
// get current cats
$postCats = $post->categories->pluck('id')->toArray();
// IF YOU DONT WANT CAT COME FROM POST
// YOU CAN HARD CODE THEM $postCats = ['2']
// here 2 is id of category
// use this cats to scope
$prevPost = $post->isPublished()->applySibling(1)
->FilterCategories($postCats)->first();
// check if nprevious ext is not availabe then return false
if(!$prevPost) {
return false;
}
// create page link here same page
$postPage = $this->page->getBaseFileName();
// set URl so we can direct access .url
$prevPost->setUrl($postPage, $this->controller);
// set Cat URl so we can use it directly if needed
$prevPost->categories->each(function($category) {
$category->setUrl($this->categoryPage, $this->controller);
});
return $prevPost;
}
In Markup area you can add this code.
{% component 'blogPost' %}
{% set nextPostRecord = this.controller.pageObject.nextPost(blogPost.post) %}
{% set previousPostRecord = this.controller.pageObject.previousPost(blogPost.post) %}
{% if previousPostRecord %}
Previous
{% endif %}
{% if nextPostRecord %}
Next
{% endif %}
This will respect category and show only that category posts
If any doubt please comment.

ng-repeat only displays final element

I am using ng-repeat in my html to display the title of each 'workbook' object in an array that is on the scope. For some reason, the third title is being displayed three times. There are three objects in this test list, so it is iterating through the correct number of times. Here is the template html code:
<div id="list-of-workbooks" ng-controller="TableauListCtrl" class="ng-scope" >
<ul>
<li ng-repeat="workbook in workbooks" ng-click="clickWorkbook(workbook)" ng-mouseover="mouseoverWorkbook(workbook)" class="ng-binding"> {{ workbook.getTitle() }} </li>
</ul>
</div>
The output looks like this:
Workbook 3 Title
Workbook 3 Title
Workbook 3 Title
Is my error in the syntax? Thanks!
EDIT: It is also possible that the error occurs when the list is made. Each title is read from an XML Document (that long chain of calls returns the correct title) and is used to set the title of a Workbook (a custom service), which is then added to the list. Are there any error in this code? It is from the application module.
var title;
var workbooks = [];
for (var i = 0; i < workbooksData.length; i++) {
var workbook = Workbook;
title = workbooksData[i].getElementsByTagName("name")[0].childNodes[0].nodeValue;
workbook.setTitle(title);
workbooks[i] = workbook; // add a workbook with each title to the array of Workbooks
}
return workbooks;
Could it have something to do with the way angular listens to changes in the model, as is suggested in this question's accepted answer, in the second bullet point? That is pretty beyond my scope of understanding, so if someone could point me in the right direction to learn more I would appreciate it!
Try removing spaces from your div's id attribute "List of Workbooks".
You could have:
<div id="list-of-workbooks" ...>
Also, take a look at:
What are valid values for the id attribute in HTML?