sync: import texts as Markdown

This commit is contained in:
nemunaire 2018-08-17 21:18:10 +02:00 committed by Pierre-Olivier Mercier
parent be7a159815
commit c33390fa80
4 changed files with 16 additions and 6 deletions

View File

@ -35,7 +35,7 @@ Tous les textes doivent utiliser l'encodage UTF8.
+ `label = "Intitulé de la réponse"` : (facultatif, par défaut identique à `value`) ;
- `[[hint]]` : paramètres pour un indice :
* `filename = "toto.txt"` : (mutuellement exclusif avec `content`) nom du fichier tel qu'il apparaît dans le dossier `hints` ;
* `content = "Contenu de l'indice"` : (mutuellement exclusif avec `filename`) contenu de l'indice affiché ;
* `content = "Contenu de l'indice"` : (mutuellement exclusif avec `filename`) contenu de l'indice affiché, en markdown ;
* `cost = 10` : (facultatif, par défaut 1/4 des gains du challenge) coût de l'indice ;
* `title = "Foo Bar"` : (facultatif, par défaut "Astuce $id") titre de l'astuce dans l'interface ;
+ `links.txt` : webographie publiée avec les solutions
@ -214,5 +214,5 @@ Exemple `DIGESTS.txt` {#exemple-digeststxt}
---
title: Format des répertoires pour la synchronisation
author: FIC team 2019
date: "Dernière mise à jour du document : 12 mai 2018"
date: "Dernière mise à jour du document : 17 août 2018"
---

View File

@ -12,6 +12,7 @@ import (
"srs.epita.fr/fic-server/libfic"
"gopkg.in/russross/blackfriday.v2"
_ "golang.org/x/crypto/blake2b"
)
@ -69,12 +70,11 @@ func SyncExerciceHints(i Importer, exercice fic.Exercice) (errs []string) {
hint.Content = s
}
}
}
// At this point, filename should have been replaced by Content if filled, so let's ensure that
if hint.Content == "" {
} else if hint.Content == "" {
errs = append(errs, fmt.Sprintf("%q: challenge.txt: hint %s (%d): content and filename can't be empty at the same time", path.Base(exercice.Path), hint.Title, n+1))
continue
} else {
hint.Content = string(blackfriday.Run([]byte(hint.Content)))
}
// Import hint

View File

@ -7,6 +7,7 @@ import (
"strconv"
"srs.epita.fr/fic-server/libfic"
"gopkg.in/russross/blackfriday.v2"
)
// getExercices returns all exercice directories existing in a given theme, considering the given Importer.
@ -83,6 +84,10 @@ func SyncExercices(i Importer, theme fic.Theme) []string {
videoURI = ""
}
// Markdown pre-formating
statement = string(blackfriday.Run([]byte(statement)))
overview = string(blackfriday.Run([]byte(overview)))
if e, err := theme.GetExerciceByTitle(ename); err != nil {
if ex, err := theme.AddExercice(ename, fic.ToURLid(ename), path.Join(theme.Path, edir), statement, overview, nil, gain, videoURI); err != nil {
errs = append(errs, fmt.Sprintf("%q: error on exercice add: %s", edir, err))

View File

@ -7,6 +7,7 @@ import (
"srs.epita.fr/fic-server/libfic"
"github.com/julienschmidt/httprouter"
"gopkg.in/russross/blackfriday.v2"
)
// getThemes returns all theme directories in the base directory.
@ -67,8 +68,12 @@ func SyncThemes(i Importer) []string {
}
}
// Format authors
authors_str := strings.Join(authors, ", ")
// Format overview (markdown)
intro = string(blackfriday.Run([]byte(intro)))
if theme.Name != tname || theme.Authors != authors_str || theme.Intro != intro {
theme.Name = tname
theme.Authors = authors_str