Xpath expression to browse to next page - html

I am trying to write an XPATH expression that finds the next page URL OR element on this page to navigate to the next page.
It looks something like as follows, where 1, 2, 3, ..., n, and 'More' navigates to pages
Page 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | More
Page source as follows:
<table><tr><td><br />
<p>Page <a href='browse.html?&id=0&count=0'>1</a> | <a href='browse.html?&id=0&count=20'>2</a> | <a href='browse.html?&id=0&count=40'>3</a> | <a href='browse.html?&id=0&count=60'><strong>4</strong></a> | <a href='browse.html?&id=0&count=80'>5</a> | <a href='browse.html?&id=0&count=100'>6</a> | <a href='browse.html?&id=0&count=120'>7</a> | <a href='browse.html?&id=0&count=140'>8</a> | <a href='browse.html?&id=0&count=160'>9</a> | <a href='browse.html?&id=0&count=180'>10</a> | <a href='browse.html?&id=0&count=200'>More</a> </p>
</td></tr></table>
I've tried writing a few but to no avail:
//table/tbody/tr/td/table/tbody/tr/td/p
//td/p
Any suggestions would be greatly appreciated, thank you

first of all, pagination or even visiting any level of a site, totally depends on each site. So there isn't a general way to paginate any site, with any tool.
Now, talking about this specific case, it looks like the site pagination only depends on the count url variable, so you can emulate pagination very easily with just a counter, no need to use xpath or get any part of the html:
browse.html?&id=0&count=0 , count=(0*1) + 20
browse.html?&id=0&count=20 , count=(1*1) + 20
browse.html?&id=0&count=40 , count=(2*1) + 20
...
If you need xpath this should return all your links:
//a/#href
And if you want an index to iterate with xpath, it could also be done with:
//a[1]/#href
//a[2]/#href
...

Related

Jekyll change element based on how you got to post (click order)

Right now I have a Jekyll site theme that allows users to filter posts by selecting tags.
If they are on the home page, it shows all posts and if they have a tag selected it shows only the posts with that tag.
When selecting a post, a new view appears below the post list and tag list which displays the post content. However when this happens, any filtering inside the Post List element goes away.
TAG1 SELECTED POST FROM TAG1 SELECTED
<URL>/tag/tag1 <URL>/POST
+---------+--------------------+ +---------+--------------------+
| Home | Post List | | Home | Post List |
| - Tag1 | <FILTERED ON TAG1> | ---\ | - Tag1 | <SHOWS ALL POSTS> |
| - Tag2 | | ---/ | - Tag2 |<NO LONGER FILTERED>|
+---------+--------------------+ +---------+--------------------+
| POST CONTENT |
| |
+------------------------------+
I have also been able to change the code so that when selecting a tag, then selecting a post, the Post List shows only posts that also contain that tag. However, with this change, it breaks if on the Home page (no tag) and I click a post; the Post List becomes filtered based on the tag associated with the selected post instead of showing all posts. (Note: For my blog I only ever plan on having one tag per post)
HOME SELECTED POST FROM HOME SELECTED
<URL>/ <URL>/POST
+---------+--------------------+ +---------+--------------------+
| Home | Post List | | Home | Post List |
| - Tag1 | <SHOWS ALL POSTS> | ---\ | - Tag1 | <FILTERED ON TAG1> |
| - Tag2 | | ---/ | - Tag2 | <IS NOW FILTERED> |
+---------+--------------------+ +---------+--------------------+
| POST CONTENT |
| |
+------------------------------+
My question is, is there a way in Jekyll to display a post and change the Post List based on how you got to the post?
For instance, if I am on the Home page (that has no filters), and I click a post from the unfiltered Post List, I would like to view the post while keeping the Post List the same (stay unfiltered showing all posts). In addition to that, however, if I click Tag1 in the tag list then click a post from the now filtered Post List, I would like to view the post while keeping the Post List the same (continue to filter all posts on tag1). See the wireframe below for visual explanation.
Is this at all possible using Jekyll and its corresponding tools (Front Matter, Liquid...)? Or would I require a plugin of some kind?
Any help is greatly appreciated.
Yes, you can do that with Jekyll by using a generator plugin. But I think that this introduces unnecessary complication to your navigation and content duplication.
Other solutions can be to go dynamic server side or use some javascript client side, but this is still useless complications.
********** Home *******************
Last posts * TAGS
* - tag 1
(maybe some pagination) * - tag 2
*
Tag Page
********** Tag : tag 1 *************
Last posts for Tag 1 * TAGS
* - tag 1
(maybe some pagination) * - tag 2
*
Post page
********** Post page ***************
Post content * TAGS
Author, Date, Tag : tag 1 * - tag 1
* - tag 2
Post content *
***************************
Post tagged : tag 1 *
- post 1 *
- ... *
And you're done with a simple solution anybody can understand and with no useless complication.

Vapor render html from MySQL

I'm using vapor framework and created a table with longText type in mysql & store text with html tags in it,
+----+----------------------+
| id | content |
+----+----------------------+
| 1 | <b>title</b>sometext |
+----+----------------------+
now when i show them in leaf, it's shows with html tags like:
<b>title</b>sometext
My Leaf file:
but i want to show like:
title sometext
how can i do this?
thanks
Try something like
<pre class="item-body-text-pre">#raw(post.content)</pre>
You can use #raw(<yourVariableHere>) to insert unescaped text.

Is it semantically correct to put a table row <tr> inside an <a> tag?

This table contains data about a certain set of elements and I want every field of the row or else all the row altogether to allow the user to access the detail of each element. The thing is that I don't know how to proceed, I either:
Put the entire row inside an <a>:
<table>
<tr>…</tr>
<tr>…</tr>
…
</table>
Or just put all the contents of every cell into an <a>:
<table>
<tr>
<td>…</td>
<td>…</td>
</tr>
…
</table>
Of course I'd prefer the first one, but I don't know wether or not it'd be correct to do that.
This is one of the source from I got the idea of surrounding the row in an anchor tag:
HTML5: Wrap Block-Level Elements with A’s
Update:
I think I have to be a little bit more clear on this, the table holds data to display an overview of the Users in the system:
+----+------+-------+
| Id | Name | Score |
+----+------+-------+
| 1 | Foo | 10 |
| 2 | Bar | 8 |
| 3 | Baz | 5 |
| … | … | … |
| n | Zzz | 0 |
+----+------+-------+
So I think it's correct to use a table, but each user has more than 3 fields of related information, so I would use a link to reach every user's detail (15+ fields) that'd otherwise be too much to display on a single row on a table (e.g. a 'comment' field of 2048+ characters); that's why I came up to the idea of displaying a link to each user's detal. Of course I don't care if the entire row is clickable, I just want to clear up the code a little bit by not having to surround all the data of every field into an <a>. Another solution would be to create an extra cell to specifically hold a link to the user's detail, like this:
+----+------+-------+-------------------------+
| Id | Name | Score | Options |
+----+------+-------+-------------------------+
| 1 | Foo | 10 | (detail) (misc. option) |
| 2 | Bar | 8 | (detail) (misc. option) |
| 3 | Baz | 5 | (detail) (misc. option) |
| … | … | … | … |
| n | Zzz | 0 | (detail) (misc. option) |
+----+------+-------+-------------------------+
But I don't know if that would be appropiate according to any user-experience guidelines too (in which case I think is less strict than any semantical rules, and a more sensible solution). Of couse I would include several <a> in the same field (table cell) for every different option, but I think that doesn't go against any semantical rule.
If you apply a link to the <tr> element, clicking anywhere on the row will send the user to the link. This includes space that isn't a table cell, like the cell borders.
The same applies to the <td> element. Putting it inside links the text only, putting it on the outside links the whole element.
<td></td> //Links whole cell
<td> </td> //Only links text inside <a>
Both your options work, but they should do different things. Generally, tagging a whole table row is semantically incorrect, as that leads to link overlap and other problems.
Alternatively...
You can use a bit of JavaScript instead:
<table>
<tr onclick="window.location.replace='...'"></tr>
</table>
More about it: Link entire table row?
Your first code is invalid markup, as a <td> can be the child of only a <tr>. You could use your second code, but I would recommend using some JavaScript, like this:
for (i = 0; i < document.querySelectorAll('td').length; i++) {
document.querySelectorAll('td')[i].addEventListener('click', function() {
window.location.href = this.getAttribute('data-link');
});
}
<td data-link="http://example.com">text and content</td>
Your second option is the semantically correct way to do it. You probably wouldn't have needed the table in the first place if all you were going to do was add anchor elements to it. You could have just added them into two separate spans.
If you want to "link" the entire "row", then it sounds likely that you don't actually have tabular data, and should consider something other than a table element.

MySQL. Way to compose query with "LIKE" which will work similar as url regular expression

for example I have table 'urls'
urls:
___________________________________________
| id | href |
+--------+--------------------------------|
| 1 | /a/b/c/d/e/f/g/ |
+--------+--------------------------------|
| 2 | /a/b/g/ |
+--------+--------------------------------|
| 3 | /a/c/g/ |
+--------+--------------------------------|
| 4 | /a/d/g/ |
+--------+--------------------------------|
| 5 | /a.php?code=g |
+--------+--------------------------------|
| N | anyUrlString |
+--------+--------------------------------|
I wanna select urls which have special format, for example (like ROUTE in popular PHP frameworks)
"/a/#anyparam/g"
so: WHERE href LIKE '/a/%/g'
but it also will select row with id 5, 1..
How to compose LIKE statement to I can get only URI enabled values in #anyparam ?
must be something like this /a/[%, but not ('/','?','\')]/g but what exactly?
Thanks for any proposition!
P.S. Do not propose to use regular expression (it don't use indexes)!
Can you use multiple clauses?
LIKE '/a/%/g' AND NOT LIKE '/a/%?%/g' ....
Chain some "exceptions" together, attacking cases that do not match. It's hard to come up with a general case, with your limited sample set. An EXPLAIN will show if Indexes are still in use.
String and pattern taken from your code:
SELECT 1 WHERE '/a.php?code=g' LIKE '/a/%/g'
^ should not give you anything, since the string your testing doesn't end in /g, it ends with =g.
But an often overlooked ability of LIKE is negative character-classes. Unfortunately they are not variable-length, they always only represent 1 character, but you could REPEAT() them:
LIKE '/a/' + REPEAT('[^/?\]', LEN(#someVar)) + '/g'

Concatentate all rows / alt. find using a regex across all rows

I have a table like this:
+----+---------------------------------------------------+
| id | value |
+----+---------------------------------------------------+
| 1 | My favourite website is http://stackoverflow.com/ |
| 2 | This text doesn't have a link! :( |
| 3 | Hi! A link! http://www.google.com/ |
+----+---------------------------------------------------+
But of course with many rows. What I really want is a list of all the URLs in the fields. In reality they are blog posts, so some will have more than one link. I'm only interested in external links (i.e. start with (/http(s)?/) ).
So, my first thought was to perform a SQL query that returns something like:
My favourite website is http://stackoverflow.com/,This text doesn't have a link! :(,Hi! A link! http://www.google.com/
so I can use regex in PHP.
How do I write that query?
Alternatively, it would be great to go straight to list of URLs with SQL, but I suspect that might be too hard due to the multiple links thing.
Any ideas?
use GROUP_CONCAT
SELECT GROUP_CONCAT( value )
FROM tableName
SQLFiddle Demo
OTHER SOURCE
GROUP_CONCAT