Local jekyll cannot load unicode urls - url

My Local Jekyll's version is 4.0.0. and OS is Windows 10
I wanna access to 'http://localhost:4000/문제풀이/문제풀이/', but I can't. only shows 404page.
On the other hand, github pages's blog url 'https://neomindstd.github.io/문제풀이/문제풀이/' is accessible.
Below is Yaml Front Matter of '2020-02-11-문제풀이.md'
---
title: "문제풀이 테스트"
excerpt: "테스트다"
categories:
- 문제풀이
tags:
- Blog
date: 2020-02-09 KST 04:34 +0900
toc: true
toc_sticky: true
toc_label: "목차"
published: true
---
part of _config.yml
# Outputting
permalink: /:categories/:title/
paginate: 5 # amount of posts to show
paginate_path: /page:num/
timezone: Asia/Seoul # https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
so, created: .site/문제풀이/문제풀이/index.html
I've tried solution.
add the _plugins/post.rb.
# https://github.com/jekyll/jekyll-help/issues/129#issuecomment-61255284
# https://stackoverflow.com/questions/41941320/jekyll-encoding-name-of-category-special-characters
# _plugins/post.rb
module Jekyll
class Post
# override post method in order to return categories names as slug
# instead of strings
#
# An url for a post with category "category with space" will be in
# slugified form : /category-with-space
# instead of url encoded form : /category%20with%20space
#
# #see utils.slugify
def url_placeholders
{
:year => date.strftime("%Y"),
:month => date.strftime("%m"),
:day => date.strftime("%d"),
:title => slug,
:i_day => date.strftime("%-d"),
:i_month => date.strftime("%-m"),
:categories => (categories || []).map { |c| Utils.slugify(c) }.join('/'),
:short_month => date.strftime("%b"),
:short_year => date.strftime("%y"),
:y_day => date.strftime("%j"),
:output_ext => output_ext
}
end
end
end
but It doesn't work.
So, how to access unicode url on local?

Related

How can I stop rails globalize from falling back to the fallback locale on just one field?

We use the globalize gem and have included Rails.application.config.i18n.fallbacks = [:en] in config/initializers/i18n.rb so that the user sees the English translation of a field if one does not exist in their own language.
That means we see this behavior, as expected:
class Post < ActiveRecord::Base
translates :title, :name
end
puts post.translations.inspect
# => [#<Post::Translation id: 1, post_id: 1, locale: "en", title: "Globalize rocks!", name: "Globalize">,
#<Post::Translation id: 2, post_id: 1, locale: "nl", title: '', name: nil>]
I18n.locale = :en
post.title # => 'Globalize rocks!'
post.name # => 'Globalize'
I18n.locale = :nl
post.title # => ''
post.name # => 'Globalize'
In just one place where we are displaying "posts", the client asked us to not show anything if there is no translation for the "name". Is there a built in way to do this? I.e.:
I18n.locale = :nl
post.title # => ''
post.name_if_translated # => nil
I did find one workaround:
post.name_translations[I18n.locale]
But maybe there's a better way?

`Apartment::Tenant.switch!` during `bin/rails console` using `pry`

when console is launched
while at console prompt
How it should work?
See the output here. Simple, quick methods. T.me (current tenant), T.names (tenants in the DB), ...
Launch, ask for tenant selection, set
$ bin/rails c
Running via Spring preloader in process 11233
Loading development environment (Rails 5.1.5)
(1.9ms) SELECT "public"."tenants"."subdomain" FROM "public"."tenants" WHERE "public"."tenants"."deleted_at" IS NULL ORDER BY "public"."tenants"."created_at" DESC
Available tenants: {0=>"public", 1=>"local"}
Select tenant: 1
You are now Tenant 'local'
Frame number: 0/24
Switch tenant
[1] [my-project][development] pry(main)> T.ask
Available tenants: {0=>"public", 1=>"local"}
Select tenant: 0
You are now Tenant 'public'
=> nil
Switch again
[2] [my-project][development] pry(main)> T.ask
Available tenants: {0=>"public", 1=>"local"}
Select tenant: 1
You are now Tenant 'local'
=> nil
Current tenant
[3] [my-project][development] pry(main)> T.me
=> "local"
Tenant we can quickly switch to
[4] [my-project][development] pry(main)> T.hash
=> {0=>"public", 1=>"local"}
Tenant names
[5] [my-project][development] pry(main)> T.names
=> ["local"]
Is abc a tenant?
[6] [my-project][development] pry(main)> T.exists? 'abc'
=> false
Is local a tenant?
[7] [my-project][development] pry(main)> T.exists? 'local'
=> true
Note: This is not tested thoroughly. Please test before using. This code just gives you some idea, how I have been using these small shortcuts to save time during development. Thank you for reading.
Put it inside <project-root>/.pryrc
# What is it?
# => Helper methods for Apartment::Tenant gem
# How does it work?
# * bin/rails console => auto-loads and asks to switch tenant
# * T.ask => anytime in console, to switch tenant from a list
# * T.me => same as Apartment::Tenant.current
# * T.hash => hash of tenants. Example: { 0 => "public", 1 => "tenant-a" }
# * T.names => array with all existing tenant names from DB
# * T.exists?(arg) => returns true/false if `arg` exists as tenant in DB
# * T.switch!(arg) => same as Apartment::Tenant.switch!
require "rubygems"
# convenience class
class T
class << self
# ['tenant1', 'tenant2', ...]
def names
##names ||= Apartment.tenant_names.sort
end
# { 0 => 'public', 1 => 'tenant1', ...}
def hash
##hash ||= { 0 => 'public' }.merge(
(1..(T.names.length)).to_a
.product(T.names)
.to_h
)
end
def switch! arg
Apartment::Tenant.switch!(arg) if T.hash.value?(arg)
end
# current tenant
def me
Apartment::Tenant.current
end
def exists? arg
T.names.include? arg
end
# ask to switch the tenant
def ask
WelcomeClass.select_tenant
end
end
end
# select tenant when entering console
class WelcomeClass
def self.select_tenant
puts "Available tenants: #{T.hash}"
print "Select tenant: "
tenant = gets.strip # ask which one?
unless tenant.empty?
# by name
if T.exists?(tenant)
T.switch!(tenant)
# by index position
# string has digit + tenant index present
elsif tenant[/\d/].present? && T.hash.key?(tenant.to_i)
T.switch!(T.hash[tenant.to_i])
# not found = no action
else
puts "Tenant not found in list '#{tenant}'"
end
end
# announce current tenant
puts "You are now Tenant '#{T.me}'"
end
end
# run the code at `bin/rails console`
Pry.config.exec_string = WelcomeClass.select_tenant
An update is needed for the accepted answer: the T 'hash' method is creating a hash with the right number of keys but the values for all keys are duplicated with the last tenant name (0 => 'public', 1 => 'test', 2 => 'test' .. x => 'test'). Here's a working 'hash' method:
def hash
##hash ||= Hash[(0..T.names.size - 1).zip T.names]
end
bazfer answer is partially correct, it was forgotten public tenant
def hash
##hash ||= { 0 => 'public' }.merge(Hash[(1..T.names.size).zip T.names])
end
Please add to bazfer answer and to accepted answer

Middleman i18n not working

I'm newbie using ruby and middleman, I've created my project and all are working fine, but when I go to /es path I don't get any translation. I've searched for info without any results and tried to move code between folders testing configs and nothing.
My folder structure is:
|locales
|---en.yml
|---es.yml
|source
|es
|---index.html.haml
|layouts
|---layout.html.haml
|partials
|_header.html.haml
|_navigation.html.haml
|---index.html.haml
My YAML files
en.yml
en:
home: 'Home'
es.yml
es:
home: 'Inicio'
My HAML
%nav
= link_to t(:home), '/', class: "#{'active' if current_page.url == '/'}"
= link_to 'Portfolio', '/portfolio', class: "#{'active' if current_page.url == '/portfolio/'}"
= link_to t(:skills), '/skills', class: "#{'active' if current_page.url == '/skills/'}"
= link_to t(:about), '/about', class: "#{'active' if current_page.url == '/about/'}"
= link_to t(:contact), '/contact', class: "#{'active' if current_page.url == '/contact/'}"
My config
config.rb
###
# Page options, layouts, aliases and proxies
###
# Per-page layout changes:
#
# With no layout
page '/*.xml', layout: false
page '/*.json', layout: false
page '/*.txt', layout: false
# With alternative layout
# page "/path/to/file.html", layout: :otherlayout
# Proxy pages (http://middlemanapp.com/basics/dynamic-pages/)
# proxy "/this-page-has-no-template.html", "/template-file.html", locals: {
# which_fake_page: "Rendering a fake page with a local variable" }
# General configuration
set :partials_dir, 'partials'
activate :i18n, :templates_dir => 'partials'
activate :directory_indexes
# Reload the browser automatically whenever files change
configure :development do
activate :livereload
end
###
# Helpers
###
# Methods defined in the helpers block are available in templates
# helpers do
# def some_helper
# "Helping"
# end
# end
# Build-specific configuration
configure :build do
# Minify CSS on build
activate :minify_css
# Minify Javascript on build
activate :minify_javascript
end
I couldn't write a comment, but I think this might be the reason, your es.yml is wrong, since it starts en:
en:
home: 'Inicio'
Shouldn't it be
es:
home: 'Inicio'
I know this question is months old but I just had the same problem, looked all over the web for hours trying to find and answer and managed to fix the issue by adding these parameters after activating i18n:
config.rb
configure :build do
activate :i18n,
:mount_at_root => 'en',
:lang_map => { :'en' => 'en', :'es' => 'es' },
:path => '/'
end
Obviously, if you want "es" to be your default, change mount_at_root.
Hope this helps.
I achieved localized paths with separate URLs for English and Spanish by
adding index.es.html.erb in the root of the source directory
and setting activate :i18n, :path => "/:locale/" in the config.rb
In the browser, my language selector sends users to / or /es:
English
http://website.com/
Spanish
http://website.com/es
Folder structure
|data
|---home.json
|locales
|---en.yml
|---es.yml
|source
|---index.html.erb
|---index.es.html.erb
|---_slide.erb
|---config.rb
config.rb
configure :build do
activate :i18n, :path => "/:locale/"
activate :directory_indexes
...
end
slide.erb
Using t as a shortcut for I18n.t, I dynamically reference the translated value through the data.
<%= link_to t([data.link.text]),
data.link.href,
:id => data.link.id,
:class => 'btn btn-primary btn-lg btn-dark'
%>
home.json
The value of "text" correlates to the key in the .yml files.
{
"slides": [
{
"text": "slides.learnMore",
...
},
...
]
}
en.yml
en:
slides:
learnMore: "LEARN MORE"
...
es.yml
es:
slides:
learnMore: "APRENDE MÁS"
...
Move all your .erb.html that require to be duplicated per language to the folder: /source/localizable as explained in the docs:
https://middlemanapp.com/advanced/localization/#localizable-templates
You can change this folder name using the modifier: templates_dir:
# Look in `source/language_specific` instead
activate :i18n, :templates_dir => "language_specific"

How to "crawl" only the root URL with Anemone?

In the example below I would like anemone to only execute on the root URL (example.com). I am unsure if I should apply the on_page_like method and if so what pattern I would need.
require 'anemone'
Anemone.crawl("http://www.example.com/") do |anemone|
anemone.on_pages_like(???) do |page|
# some code to execute
end
end
require 'anemone'
Anemone.crawl("http://www.example.com/", :depth_limit => 1) do |anemone|
# some code to execute
end
You can also specify the following in the options hash, below are the defaults:
# run 4 Tentacle threads to fetch pages
:threads => 4,
# disable verbose output
:verbose => false,
# don't throw away the page response body after scanning it for links
:discard_page_bodies => false,
# identify self as Anemone/VERSION
:user_agent => "Anemone/#{Anemone::VERSION}",
# no delay between requests
:delay => 0,
# don't obey the robots exclusion protocol
:obey_robots_txt => false,
# by default, don't limit the depth of the crawl
:depth_limit => false,
# number of times HTTP redirects will be followed
:redirect_limit => 5,
# storage engine defaults to Hash in +process_options+ if none specified
:storage => nil,
# Hash of cookie name => value to send with HTTP requests
:cookies => nil,
# accept cookies from the server and send them back?
:accept_cookies => false,
# skip any link with a query string? e.g. http://foo.com/?u=user
:skip_query_strings => false,
# proxy server hostname
:proxy_host => nil,
# proxy server port number
:proxy_port => false,
# HTTP read timeout in seconds
:read_timeout => nil
My personal experience is that Anemone was not very fast and had a lot of corner cases. The docs are lacking (as you have experienced) and the author doesn't seem to be maintaining the project. YMMV. I tried Nutch shortly but didn't play aroud as much but it seemed faster. No benchmarks, sorry.

Ruby add_item for eBay

I am attempting to write a ruby on rails app that posts an item to eBay. Cody Fauser/Garry Tan have a gem called ebayApi which is built on top of the ebay gem. When I attempt to post an item, I am getting an error back from ebay that says the condition ID is required for this category. I have found a category that does not require the condition, and I can post to that category. Searching through the eBay API documentation, I have found a tag conditionID under the "item" class. However, in the documentation for ebayAPI, there is no such tag. Looking back at the ebay API documentation, there is an older way to specify condition, using lookup_attributes. I have noted that the return xml is coming in API version 745, and Garry Gan's updated of the ruby interface is running version 609. I have tried using the lookup, and seem to get the same error (condition required). I am using the following code to specify the item:
#ebay = Ebay::Api.new :auth_token => #seller.ebay_token
item = Ebay::Types::Item.new( :primary_category => Ebay::Types::Category.new(:category_id => #ebayTemplate.categoryID),
:title => #ebayTemplate.name,
:description => #ebayTemplate.description,
:location => #ebayTemplate.location,
:start_price => Money.new((#ebayTemplate.startPrice*100).to_d, #ebayTemplate.currency),
:quantity => 1,
:listing_duration => #ebayTemplate.listingDuration,
:country => #ebayTemplate.country,
:currency => #ebayTemplate.currency,
:payment_methods => ['VisaMC', 'PayPal'],
:paypal_email_address => '********#gmail.com',
:dispatch_time_max => 3,
:lookup_attributes => [Ebay::Types::LookupAttribute.new( :name => "Condition", :value => "New")],
# :attribute_sets => [
# Ebay::Types::AttributeSet.new(
# :attribute_set_id => 2919,
# :attributes => [
# Ebay::Types::Attribute.new(
# :attribute_id => 10244,
# :values => [ Ebay::Types::Val.new(:value_id => 10425) ]
# )
# ]
# )
# ],
:shipping_details => Ebay::Types::ShippingDetails.new(
:shipping_service_options => [
# ShippingServiceOptions.new(
# :shipping_service_priority => 2, # Display priority in the listing
# :shipping_service => 'UPSNextDay',
# :shipping_service_cost => Money.new(1000, 'USD'),
# :shipping_surcharge => Money.new(299, 'USD')
# ),
Ebay::Types::ShippingServiceOptions.new(
:shipping_service_priority => 1, # Display priority in the listing
:shipping_service => #ebayTemplate.shipSvc,
:shipping_service_cost => Money.new((#ebayTemplate.shipSvcCost*100).to_d, #ebayTemplate.currency),
:shipping_surcharge => Money.new((#ebayTemplate.shipSurcharge*100).to_d, #ebayTemplate.currency)
)
],
:international_shipping_service_options => [
Ebay::Types::InternationalShippingServiceOptions.new(
:shipping_service => 'USPSPriorityMailInternational',
:shipping_service_cost => Money.new((#ebayTemplate.shipSvcCost*100).to_d, #ebayTemplate.currency),
:shipping_service_priority => 2,
:ship_to_location => #ebayTemplate.shipToLocation
)
]
),
:return_policy => Ebay::Types::ReturnPolicy.new (
:description => 'this product for suckers only!',
:returns_accepted_option => 'ReturnsAccepted'
)
#:condition_id => 1000
)
#response = #ebay.add_item(:item => item)
As you can see, it is just a mutation of the example given by Cody Fauser. The condition_id at the bottom will bring up an error as there is no such attribute. It seems to me there is no facility for this in the gem since the requirement came into existence after the gem was created. I have not been able to find any other gems to connect with ebay. I have also noticed, there are very little complaints about this even though people are still downloading the gem (10 people downloaded it today). I think there are quite a number of people writing for ebay. Is there a key word I am missing to specify the condition? A work around that people have been using? Another gem I have missed?
There is an existing item_conditions_codes.rb in the gem's type directory and only has two values New and Used. Guess you could add more values in there. However still needs mapping to ID's per the updating (and changed from Attributes) method
You have to modify in the gem library in .. ruby/1.8/gems/ebayapi-0.12.0/lib/ebay/types/item.rb
and add the following new lines
# added to allow ConditionID to be pushed into XML
numeric_node :condition_id, 'ConditionID', :optional => true
then in your ruby ebay code use the following convention
:condition_id => 1500,
At least that seems to work for me right now.

Resources