to_s end # Support a :fragment or :anchor option just like Padrinoįragment = options_hash || options_hash uri. encode ( relative_path_from_resource ( this_resource, resource_url, effective_relative ) ) else resource_url end end # Support a :query option that can be a string or hash path = if this_resource :: Addressable :: URI. url if resource end elsif options_hash & uri. # File 'middleman-core/lib/middleman-core/util/files.rb', line 110 def find_related_files ( app, files ) return if files. encode ( relative_path_from_resource ( options_hash, result, options_hash ) ) result_uri = :: Middleman :: Util. config, path ) end end final_result = :: Addressable :: URI. by_destination_path ( dest_path ) result = if resource resource. merge ( relative: false ) ) resource = app. # relative path, since it only takes absolute url paths.ĭest_path = url_for ( app, path, options_hash. To get Slim working with Middleman Add gem 'slim' to your projects gemfile go to command line, in your project folder and gem install bundler In the config. path # Ensure the url we pass into by_destination_path is not a start_with? ( ' data: ' ) raise ArgumentError, ' #asset_url must be run in a context with current_resource if relative: true ' if options_hash & ! options_hash uri = :: Middleman :: Util. It’s okay to give up if things are getting frustrating, and it’s okay to ask for help.# File 'middleman-core/lib/middleman-core/util/paths.rb', line 112 def asset_url ( app, path, prefix = ' ', options_hash = :: Middleman :: EMPTY_HASH ) # Don't touch assets which already have a full path Writing new features into software can be overwhelming, and stepping back for a break is usually the right answer. ( Update: I’ve added documentation to all the code and linked to the relevant code in the readme.) I’m sure there are ways this could be more idiomatically done. The pull request is here, so feel free to comment on anything that you’d like clarification on or that you have a suggestion about. It can never hurt to have someone double-check things for you. I pinged Orta on the pull request and asked for a second opinion. It crosses the dynamic-to-static barrier, which isn’t something many other features of static sites need to do.Īfter submitting the pull request, I realized I had been working into the late evening, that I’d had a beer or two, and that maybe pushing code to production wasn’t the best thing to do. Then client-side Javascript downloads that index and uses lunrjs to run queries against it. Ruby code uses Javascript to generate a search engine index of the content of my entire site. Distinct from search engines in general, server-side static site search is a very interesting problem in its own right. Some fiddling with CSS and lining things up, I had a ready PR. After looking up some jQuery syntax, I had something that worked. I understood what it was doing on the Ruby side, and concentrated just on the Javascript. Actually it was the original extension I tried but I couldn’t get it working. I submitted a work-in-progress pull request and gave up again.Īfter a little break and some food, I went back and looked into a different extension. It turns out that I didn’t know enough Javascript to use a Javascript-based search engine. I ended up reading the source code of one to understand exactly how it worked. There are a few Middleman extensions that integrate lunrjs search into static sites, but I couldn’t get any to work for me because I didn’t understand how they worked. I think the sun-vs-moon metaphor for server-vs-client search engines is really apt. ![]() lunrjs is a Javascript-based search engine, which claims to be:Ī bit like Solr, but much smaller and not as bright. But for a site like mine, a client-side search engine written in Javascript can be a suitable solution. Running search on servers makes sense for DuckDuckGo and Google because their search engines are trying to cover the whole internet. It’s a faster, easier, and more secure way of serving web pages that don’t need dynamism, but it does mean that you can’t run server code when a page is fetched. ![]() This site, just like all static sites like those built with Middleman, is generated on a computer before being served statically. Most search engines run on servers and not the browser client. (Note: The original “the day” was two weeks ago but I had given up in frustration.) Neat idea, it wasn’t high on my list of priorities at the time, but maybe I’d get to it someday. A few months ago, someone opened an issue asking for a site search on my blog.
0 Comments
Leave a Reply. |