Here’s how to modify the _s (“underscores”) WordPress theme to support different sidebars that trigger depending on the page being viewed. There are plug-ins for this, but some of them are shady or just break the UI.
(E.g., Custom Sidebars notably made it impossible for me to save widget content, because its donation bar’s shitty CSS prevents users from being able to scroll far enough down to hit the button. Good times!)
Anyway, here’s the run down:
Edit your functions.php to register more sidebars.
Edit your sidebar.php file to throw in conditionals to determine how you invoke dynamic_sidebar().
Edit the corresponding widgets.
1 2 3 4 5 6 7 8 9 10 |
|
Registering additional sidebars in functions.php is pretty straightforward. Here’s an example of how to register a second sidebar with a semantically meaningful name.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
I was initially tempted to use register_sidebars() instead, but it would lead to a bunch of sidebars named by number (e.g., sidebar-1, sidebar-2, etc.) which would be a maintenance hazard in that the names would lack any sort of semantic meaning, forcing you to look things up. A stitch in time, and all that jazz.
1 2 3 |
|
Brief note for the uninitiated: that hideous ‘: … endif’ pairing is a PHP-idiomatic replacement for everyday curly-braces {} when the stuff between braces would have otherwise contained embedded HTML. (Yuck.)
1 2 3 4 5 6 7 8 9 |
|
The key here is nesting ifs (or using a case statement) to intelligently exploit WordPress’s conditional tags to only show a sidebar appropriate to the type of content being displayed. Said tags can be used to differentiate between pages, the blog index, categort pages, and so on, all the way down to even the individual post level. You’ve got a lot of control.
Be really cautious, here. Using things that otherwise seem they’d make sense can blow up in your face. Notably, using !dynamic_sidebar(‘sidebar-a’) || !dynamic_sidebar(‘sidebar-b’) will behave unexpectedly. Swapping &&, in the previous statement, for || does too.
Open the WordPress admin panel. Appearance -> Widgets has a pretty obvious interface that will let you set up what gets displayed in each widget.
Bam! A little hand-waving later, and you’re good to go.
]]>Canonical tags for Octopress categories and posts are slightly off. Directories (and blog posts) redirect to ending in a slash. The canonical tags produced take the form http://domain/blogdir/categories/category. The trailing slash is missing.
{% capture canonical %}{{ site.url }}{% if site.permalink contains '.html' %}{{ page.url }}{% else %}{{ page.url | remove:'index.html' | strip_slash }}{% endif %}{% endcapture %}
{% capture canonical %}{{ site.url }}{% if site.permalink contains '.html' %}{{ page.url }}{% elsif site.permalink contains category_dir %}{{ '/' | page.url | remove:'index.html' | '/' }}{% else %}{{ page.url | remove:'index.html' | '/' }}{% endif %}{% endcapture %}
Note that, if you specify
yaml _config.yml (problem)
category_dir: categories
as opposed to
yaml _config.yml (fixed)
category_dir: /categories
The canonical tags for categories will be entirely broken, taking the form: http://domain/blogdircategories/category (see: missing slash in the middle of the link). It would be more consistent to have users forego the leading slash, and to add another ’/’ | to the canonical tag for a category URL.
Meta description for the blog index takes the meta-desc of the first post, rather than contents of the description field from _config.yml. Unsure how to change this.
Posts are redirected to a trailing slash. http://domain/dir/post gets redirected to http://domain/dir/post/. This isn’t an SEO matter so much as an aesthetic one. Unsure how to change this.
2 is minor and 3’s a matter of taste, so I haven’t hunted the source of either down. Yet.
]]>1
|
|
1
|
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
|
Booyah. Better living through technology. For versions of rails older than 3.2, check out http://stackoverflow.com/a/10138878/1296445 and adapt the routes assignment accordingly.
For information about automatically regenerating the sitemap and pinging search engines via cron or upon deploy, read the sitemap generator gem’s documentation. In my case, a post-receive hook for git fit the bill well enough.
]]>1 2 3 |
|
1 2 3 |
|
Finally, in the source directory, move the /blogs/archive/index.html file to /archive/index.html. (Erase the empty blog folder, too.)
Also, in case you want the massive site-name header to link to your domain root, instead of the blog here’s what you do.
1 2 3 |
|
I don’t especially like this fix. It seems like something that should be handled with the “root” entry in config.yml. Changing “root: /blog” to “root: /” in config.yml doesn’t do the trick, and only serves to screw up the deployment.
]]>1 2 3 4 5 |
|
The default (top-to-bottom) behavior is accomplished via using “TB” instead of “LR”, or by just never specifying graph[:rankdir].
For a more in-depth example, see sample 35 from Ruby-Graphviz’s examples on GitHub.
Features undocumented by Ruby-Graphviz can occasionally be accessed. Just experiment with stuff from the Node, Edge, and Graph Attributes list on GraphViz’s site.
]]>LR(0) and SLR(1) grammars produce identical non-deterministic finite automata (NFA), and consequently, the same deterministic finite automata (DFA). However, they don’t produce the same tables.
Here’s how to build them.
Note: If the grammar’s leading non-terminal has only one production rule, skip this step.
Create a new production rule: Goal → YourOldStartingNonTerminal. E.g., convert A → ( A ) | a into:
First, rewrite the grammar as having one production rule per line. Using the above grammar, we get:
Next, “walk the dot.” For each production rule, transcribe it:
The resulting item list grows rapidly. Using our example from above, we get the following:
Quick definition: the current symbol is the symbol following the • marker.
Draw a transition from State 0 on current symbol to State 1. (In our example, this means drawing an edge, labeled A, from the 1st item to the 2nd. It would look something like this:
For each remaining item:
Next planned post on this subject: NFA to Table for LR(0) and SLR(1) Grammars
For example: the initial states for A in the above grammar are:
http://en.wikipedia.org/wiki/LL_parser
http://en.wikipedia.org/wiki/LR_parser
A bottom-up parser has two possible actions (besides “accept”):
- Shift a terminal from the front of the input to the top of the stack.
- Reduce a string α at the top of the stack to a nonterminal A, given the BNF choice A → α
Source: Louden (198).
]]>
Given an LR(1) item [A → α•Xγ, a], where X is any symbol (terminal or nonterminal), there is a transition on X to the item [A → αX•γ, a].
Given an LR(1) item [A → α•Bγ, a], where B is a nonterminal, there are ε-transitions to items [B → •Β, b] for every production B → Β and for every token b in First(γa).
Source: Louden (217-218).
1 2 3 4 |
|
Solution after the jump.
Your gem paths are probably hosed somewhere in your configuration file. The DH Wiki suggested this:
1 2 3 |
|
Chances are that those don’t jive with your RVM gempath.
I imagine this suggestion was off too:
1 2 |
|
I imagine the correct fix is unborking your gem paths. I’ll investigate this in greater depth some time down the road.
Until such a time, here’s how to get around the issue.
1
|
|
This will get rails to look in the RAILSROOT/vendor/bundle folder instead of your system path. Stick this in your git post-receive hook, or add it as a task to whatever deployment system you’re using, to have it execute every time you push. As solutions go, this is slow and crappy, but probably won’t kill you if your updates are infrequent.
]]>Consider the possible ways to construct 2-state NFA for an alphabet = {0,1}.
Next, consider the same using 3-states.
Though repetetive, exhausting the possibilities for both 2- and 3-state non-deterministic finite automata exposes a trend. The amount of NFAs we can form using those states, #PossibleNFAs = AcceptPossibilities * TransitionPossibilities, where AcceptPossibilities = 2^#states and TransitionPossibilities = (2^#states)^(alphabetSize*#states).
Some time later, I’ll brute force the space for a 2-letter alphabet on 3 states, but for now, here my approximation of the worst-case:
1 2 3 4 5 6 7 8 9 |
|
Before determinization, it looks like this:
A little transition-heavy, but seemingly unassuming. If you turned it 90° clockwise, it would make a convincing muppet. Anyway, after determinizing it using the subset construction (and not using any minimization techniques) it looks like this:
Pretty big.
This post was primarily a formatting test. Expect more soon.
]]>