From 0ddab1b797c069061ae50f27b45d87e33a5147f5 Mon Sep 17 00:00:00 2001 From: Tunghsiao Liu Date: Sat, 31 Oct 2015 14:33:50 +0800 Subject: [PATCH] feat(template): add `site.robots` support BREAKING CHANGE: Now you can define your custom `robots.txt` records in configuration file: ```yaml robots: - "User-agent: *" - "Disallow: /ajax/" - "Disallow: /@async" - "Disallow: /log/" ``` --- _app/_posts/note/2014-06-09-creating-themes.md | 14 ++++++++++++++ _app/robots.txt | 5 ++++- _config.init.yml | 17 +++++++++++++++++ _config.yml | 10 ++++++++++ 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/_app/_posts/note/2014-06-09-creating-themes.md b/_app/_posts/note/2014-06-09-creating-themes.md index 24efb0b46..f5bfda7dc 100644 --- a/_app/_posts/note/2014-06-09-creating-themes.md +++ b/_app/_posts/note/2014-06-09-creating-themes.md @@ -203,6 +203,20 @@ Template: {{ '{% endif ' }}%} ``` +### `site.robots` + +You can define your own records in `robots.txt`. + +Config: + +```yaml +robots: + - "User-agent: *" + - "Disallow: /ajax/" + - "Disallow: /@async" + - "Disallow: /log/" +``` + ## Theme Features There're some features can be integrated into your theme. diff --git a/_app/robots.txt b/_app/robots.txt index a4d783b2d..df1c065bf 100644 --- a/_app/robots.txt +++ b/_app/robots.txt @@ -1,5 +1,8 @@ --- --- -User-agent: * +{% for post in site.robots + %}{{ post | strip }} +{% endfor %} + Sitemap: {{ '/sitemap.xml' | prepend: site.base | prepend: site.url }} diff --git a/_config.init.yml b/_config.init.yml index 98e096c08..7216486bc 100644 --- a/_config.init.yml +++ b/_config.init.yml @@ -54,6 +54,13 @@ redcarpet: - superscript - tables +# +# Jekyll plugins +# + +gems: + - jekyll-last-modified-at + # # Almace Scaffolding settings # @@ -117,3 +124,13 @@ rss_excerpt: false # Show generator credits # Default: true credits: true + +# Custom records in robots.txt +# For example: +# robots: +# - "User-agent: *" +# - "Disallow: /ajax/" +# - "Disallow: /@async" +# - "Disallow: /log/" +# Default: "User-agent: *" +robots: "User-agent: *" diff --git a/_config.yml b/_config.yml index ed8a47b92..a0e70e42d 100644 --- a/_config.yml +++ b/_config.yml @@ -124,3 +124,13 @@ rss_excerpt: false # Show generator credits # Default: true credits: true + +# Items in robots.txt +# For example: +# robots: +# - "User-agent: *" +# - "Disallow: /ajax/" +# - "Disallow: /@async" +# - "Disallow: /log/" +# Default: "User-agent: *" +robots: "User-agent: *"