NBISweden / canvas-integrations

0 stars 0 forks source link

This repository is used as the code base for all the functionality related to the transition to the Canvas LMS.

Automated transition and syncing of content from GitHub to Canvas

https://github.com/learn-co-curriculum/github-to-canvas/

Moving Markdown files to Canvas

The method below was put together by us in NBIS.

Transform Markdown to html

In order to move a markdown file from github pages to canvas, the markdown file needs to be transformed to html. That can be achieved using the docker version of pandoc. The following command will mount the current folder in the pandoc container and transform the <input_file>.md file to the <output_file>.html:

docker run --rm --volume "`pwd`:/data" --user `id -u`:`id -g` pandoc/latex <input_file.md> -o <output_file.html>

Trouble with embedding images / page width? Check the code from the Tools for Rep. Research.

Create personal token for Canvas API

The Canvas LMS provides an API, which can be used for creating/updating/deleting pages (and much more). To create a page with the html file produced in the previous step, a personal token needs to be created in the Canvas UI. Detailed instructions for creating a personal token can be found here.

In summary:

Create or update a Canvas page using the API

Finally, to create the page with the html file run the following command, replacing the personal_token with the one created in the previous step:

curl -X POST --header 'Authorization: Bearer <personal_token>' \
    https://uppsala.instructure.com/api/v1/courses/<course_number>/pages \
    --data-urlencode wiki_page[title]=<page_title> \
    --data-urlencode wiki_page[body]="$(cat <output_file>.html)"

If you then want to update the same page you will have to use a slightly modified command using PUT instead of POST that only updated the body of the specified page (notice the exact specification of the page in the URL):

curl -X PUT --header 'Authorization: Bearer <personal_token>' \
    https://uppsala.instructure.com/api/v1/courses/<course_number>/pages/<page_title> \
    --data-urlencode wiki_page[body]="$(cat <output_file>.html)"

Additional libraries