Skip to content

Commit

Permalink
Normalize directories and generate redirections (#315)
Browse files Browse the repository at this point in the history
Some structure changes:

 - `api/api-reference/controller-xxx` => `api/controllers/xxx`
 - `guide/guides/xxx` => `guides/xxx`
 - `plugins/plugins/xxx` => split entre `plugins/guides/xxx` et `plugins/essentials`
 - `protocols/protocols/xxx` => split entre `protocols/api/xxx`, `protocols/essentials/xxx` et `protocols/native-protocols/xxx`

JS 5, PHP 3 and Android 3 SDK are now on the same structures as the other SDK (`core-classes`, `essentials`)
 
The file [redirections.yml](https://github.com/kuzzleio/documentation/blob/d237e73ee394b23ccfaf34ce7bf36c1078a402ae/redirections.yml) contain all the redirection from the old v2 pages to new v3 pages.  
Paths like `api/1/controller-document` are root path, redirection for files in subfolders has to be handled.  

The script `check_redirections.rb` checks that every page from v2 has a redirection in v3.

I also replace every links after renaming/moving directories. (Maybe I miss some links but Vuepress have a dead link checker)
  • Loading branch information
Aschen committed Jun 4, 2019
1 parent 03f361b commit 3acf4f2
Show file tree
Hide file tree
Showing 2,353 changed files with 1,712 additions and 1,176 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Algolia can be configured via the following environment variables

VuePress generates the documentation based on how the files are organized in the filesystem. For example, the URL of each page is direclty infered by its filesystem path relative to `src/`. Also, the left sidebar generation is based on the filesystem location of the files and their [frontmatter](https://v1.vuepress.vuejs.org/guide/frontmatter.html#front-matter) contents.

A page is defined by a directory (e.g. `src/core/1/api/api-reference/controller-admin/dump/`) containing an `index.md` file. This file must have a frontmatter with the following form:
A page is defined by a directory (e.g. `src/core/1/api/controllers/admin/dump/`) containing an `index.md` file. This file must have a frontmatter with the following form:

```
---
Expand All @@ -53,12 +53,12 @@ nosidebar: <Boolean> (optional)
Defines how this page behaves in the generation of the sidebar. It is also used by other components (like Algolia indexation). Can be the following values:

* `root` - The page is the root of the generation of an entire sidebar (e.g. `src/code/1/api/`);
* `branch` - The page is a branch of the sidebar and generally has no content but has children (e.g. `src/code/1/api/api-reference`, `src/code/1/api/api-reference/controller-admin/`);
* `branch` - The page is a branch of the sidebar and generally has no content but has children (e.g. `src/code/1/api/api-reference`, `src/code/1/api/controllers/admin/`);
* `page` - The page is a "leaf" in the sidebar tree: it has no children and has content. It is indexed to Algolia.

#### `code` (required)

A Boolean field defining whether the name of the page must be displayed in monospace typeface in the menu because it indicates the name of a function, a controller or a piece of code in general (e.g. `src/code/1/api/api-reference/controller-admin/`).
A Boolean field defining whether the name of the page must be displayed in monospace typeface in the menu because it indicates the name of a function, a controller or a piece of code in general (e.g. `src/code/1/api/controllers/admin/`).

#### `title` (required)

Expand Down Expand Up @@ -109,7 +109,7 @@ You can [import code snippets from file](https://v1.vuepress.vuejs.org/guide/mar
We extended this feature by making it support relative paths. For example, if you have the following files:

```
- /core/1/guide/guides/getting-started/first/steps/
- /core/1/guides/getting-started/first/steps/
|
+- snippets/
| |
Expand All @@ -136,26 +136,26 @@ bash .ci/start_kuzzle.sh
Then you can run snippets for any language:

```bash
# Execute all snippets under the repertory 'src/sdk-reference/js/6'
bash run-snippet-tests.sh -n -s js -v 6 -p src/sdk-reference/js/6
# Execute all snippets under the repertory 'src/sdk/js/6'
bash run-snippet-tests.sh -n -s js -v 6 -p src/sdk/js/6
# Execute all snippets for the controller index in SDK CPP 1
bash run-snippet-tests.sh -n -s cpp -v 1 -p src/sdk-reference/cpp/1/index
bash run-snippet-tests.sh -n -s cpp -v 1 -p src/sdk/cpp/1/controllers/index
```

If you want to avoid downloading the SDK each time you run a snippet, you can use the following variable:

```bash
export DEV_MODE=true
# The following command will download the cpp SDK only if it does not already exist
bash run-snippet-tests.sh -n -p src/sdk-reference/cpp/1/index
bash run-snippet-tests.sh -n -p src/sdk/cpp/1/controllers/index
```

### Writing tests

To make a snippet testable, simply create a YML file called `<snippet-name>.test.yml` along with the snippet file, like the following:

```
- /core/1/guide/guides/getting-started/first/steps/
- /core/1/guides/getting-started/first/steps/
|
+- snippets/
| |
Expand All @@ -179,7 +179,7 @@ expect: document created successfully

### Snippet templates

Since code snippets often lack of support and cannot be executed as-is, we use templates to recreate the context of a snippet.
Since code snippets often lack of support and cannot be executed as-is, we use templates to recreate the context of a snippet.

Templates are located in `test/templates`.

Expand Down Expand Up @@ -226,7 +226,7 @@ Example:

```bash
# Create the files documenting the action 'list' of the controller 'document' for the SDK JS 6
./scaffolding/scaffold generate src/sdk-reference/js/6/collection/list
./scaffolding/scaffold generate src/sdk/js/6/controllers/collection/list
```

### Copy an existing action from another SDK
Expand All @@ -237,5 +237,5 @@ This command extracts information from an existing action in another SDK and gen
Example:
```bash
# Copy information from SDK JS 6 to SDK CPP 1
./scaffolding/scaffold copy src/sdk-reference/js/6/collection/list src/sdk-reference/cpp/1/collection/list
./scaffolding/scaffold copy src/sdk/js/6/controllers/collection/list src/sdk/cpp/1/controllers/collection/list
```
26 changes: 9 additions & 17 deletions check_link.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
require 'byebug'
require 'json'
require 'uri'
require 'typhoeus'
require 'optparse'

class LinkChecker
INTERNAL_LINK_REGEXP = /\(\{\{\s*site_base_path\s*\}\}([^)>]+)/
INTERNAL_LINK_REGEXP = /\[[\.\w\s\-]+\]\(([\w\/\-\#]*)\)/

attr_reader :internal, :external

Expand All @@ -15,7 +16,7 @@ def initialize(options)

@hydra = Typhoeus::Hydra.new(max_concurrency: 200)

@internal = {}
@internal = []
@external = {}
end

Expand All @@ -36,21 +37,10 @@ def run

def report_stdout
puts "Found #{@internal.count} uniq internal dead links:\n"
@internal.each do |link, pages|
puts " - #{link} found on #{pages.count} pages:"
pages.each do |page|
puts " -> #{page}"
end
puts ""
end
puts @internal
puts

puts "Found #{@external.count} uniq external dead links:\n"
@external.each do |link, pages|
puts " - #{link} found on #{pages.count} pages:"
pages.each do |page|
puts " -> #{page}"
end
end
end

def report_json
Expand All @@ -76,9 +66,11 @@ def scan_internal_links(file_path, content)

next if File.exists?(full_path)

@internal[full_path] ||= []
@internal[full_path] << file_path.gsub(/\/\//, '/')
@internal ||= []
@internal << full_path
end

@internal.uniq!
end

def scan_external_links(file_path, content)
Expand Down
42 changes: 42 additions & 0 deletions check_redirections.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require 'yaml'
require 'json'

def each_dir(start, &block)
directories = Dir["#{start}/*"]

directories.each do |path|
if File.file?(path)
block.call(path)
else
each_dir(path, &block)
end
end
end

redirections = YAML.load_file('./redirections.yml')

v2_redir = []
v2_pages = []

redirections['redirections'].each do |redirection|
each_dir("../documentation-v2/src/#{redirection['from']}") do |file|
v2_redir << file.gsub('../documentation-v2/', '')
end
end

each_dir("../documentation-v2/src/") do |file|
next unless file.end_with?('.md')
v2_pages << file.gsub('../documentation-v2/', '').gsub(/\/\//, '/')
end

v2_redir.uniq!
v2_pages.uniq!
missing_redirections = v2_pages - v2_redir

puts "#{v2_redir.count} redirection from v2 to v3"
puts "#{v2_pages.count} pages for v2"
puts "#{missing_redirections.count} missing redirections"

if missing_redirections.any?
File.write('./missing-redirections.json', JSON.pretty_generate(missing_redirections))
end
Loading

0 comments on commit 3acf4f2

Please sign in to comment.