Get internal tags in Ghost - ghost

Is there any way to get all internal tags in Ghost using the api and the get helper?
In my post.hbs template I can do this and it works:
{{#post}}
{{#foreach tags visibility="internal"}}
{{name}}
{{/foreach}}
{{/post}}
But in my page.hbs I tried this and it only shows tags with public visibility.
{{#get "tags" limit="all"}}
{{#foreach tags}}
{{name}}
{{/foreach}}
{{/get}}
I also tried
{{#get "tags" filter="visibility:internal"}}
and
{{#get "tags" visibility="internal"}}
but it does not return any tags.
Is this not implemented and if so why not? This would be super useful for my use case.
I did read the docs and https://themes.ghost.org/docs/get#section--fields- says that valid fields for tags are id, uuid, name, slug, description, image, created_at, created_by, updated_at, updated_by. Visibility is notably missing, does anyone know why?

You have to specify the visibility attribute when you access the tags, not when you retrieve them, in this case, it's in the foreach:
{{#get "tags" limit="all"}}
{{#foreach tags visibility="internal"}}
{{name}}
{{/foreach}}
{{/get}}
This will loop over the internal tags only. Apparently you have to get all the tags and then filter this way, I didn't find a way to get only the internal tags from the begining.

Related

Find select knowing just part of its name

In Capybara, how can I refer to a select knowing only part of its name?
I have the following piece of HTML
<select name="user[work_hours][HASH][end_hour]">
...
</select>
Where HASH is an unknown value, and I need to find the select.
Can I use a regular expression?
There are many ways to do what you want. Depending on surrounding HTML you may be able to scope the find to a section of the page that only includes the one select so you don't need to specify anything to match the select at all
find('css to locate wrapping/scoping element').find(:select)
If that's not possible you can use CSS attribute begins-with and ends-with selectors like
find('select[name^="user[work_hours]["][name$="][end_hour]"]')
If that seems too complicated you can use the :element selector type which will allow you to match on any attribute with a string or regex. This may be inefficient on large pages with many select elements.
find(:element, :select, name: /user\[work_hours\]\[.*\]\[end_hour\]/
Another solution if the options in the select are unique on the page would just be to select the option and not worry about finding the actual select element
select('text of option')

conver to html entites only not matching tags

I was using: ActionView::Helpers::SanitizeHelper.sanitize in order to get rid of some html tags, however I'm interested in convert to html entities all the non-matching tags.
For example, giving this text:
<b>this is an acceptable tag<b> <iframe>this is not acceptable</iframe>
I'm interested in get this output
<b>this is an acceptable tag<b> <iframe>this is not acceptable</iframe>
You can specify allowed tags as options to the sanitize method.
sanitize #comment.body, tags: %w(strong em a), attributes: %w(href)
Check for more information ActionView::Helpers::SanitizeHelper

How to autolink all words in a rendered text that match an item name in my database?

I have a rails app with a postgres database for articles and items. I would like that whenever I render text from an article, it can somehow scan the text and if it finds a word that matches the name of an item in my database it autolinks to that items show_path.
Any ideas? Much appreciated.
You can reason it out from first principles.
Make a little method that returns either a word, or a link to an article if the word is in the article.
def make_link(word)
item = Item.find_by(text: word.downcase)
item ? link_to(word, item_path(item_id) : word
end
Now, map all the words in the article using the method above to convert the linkable ones into links.
new_article = ActionController::Base.helpers.sanitize(article).split(' ').map{|word| make_link(word)}.join(' ').html_safe
Note the html_safe method to ensure the link tags aren't escaped when the new_article is rendered, and the sanitize method to ensure unwanted HTML tags in the source are removed.

is it possible to remove only valid tags in rails?

I'm crawling some news articles.
and I'm attempting to remove all tags inside the news title
using ActionView::Helpers::SanitizeHelper.sanitize
but if the title contains string like <scoop> some news title,
the word and <> are considered as a HTML tag and removed and the result is some news title.. it's not what i want.
is there any way to remove only valid tags?
You can try this by defining which tag. only the mentioned tags are allowed, nothing else
<%= sanitize #article.body, tags: %w(table tr td) %>

Getting a public event by id (Upcoming)

I know the id of a public yql event. Why can't I get it by simply mentioning the id in WHERE clause like this:
Click here to see my yql console
You were very close - instead of id you'll want to use the parameter event_id. Here's a modified version of your search which works:
SELECT * FROM upcoming.events WHERE event_id = "9236524" | sort(field='start_date')
For Community YQL tables like upcoming.events, you can see the allowed parameters by clicking on the "desc" link on the far right. In this case it shows that searching by event_id is one of the options:
<select>
<key name="event_id" required="true" type="xs:string"/>
</select>

Resources