in community/document-readers/spring-ai-alibaba-starter-document-reader-gitbook/src/main/java/com/alibaba/cloud/ai/reader/gitbook/GitbookDocumentReader.java [89:132]
public List<Document> get() {
GitbookClient client = new GitbookClient(apiToken, apiUrl);
List<Document> documents = new ArrayList<>();
try {
// Fetch all pages from the space
List<GitbookPage> pages = client.listPages(spaceId);
// Convert each page to a Document
for (GitbookPage page : pages) {
String content = client.getPageMarkdown(spaceId, page.getId());
// Skip pages with no content
if (content == null || content.isEmpty()) {
continue;
}
// Build metadata map
Map<String, Object> metadata = new HashMap<>();
metadata.put("path", page.getPath());
// Add additional metadata fields if configured
if (metadataFields != null) {
for (String field : metadataFields) {
switch (field) {
case "title" -> metadata.put(field, page.getTitle());
case "description" -> metadata.put(field, page.getDescription());
case "parent" -> metadata.put(field, page.getParent());
case "type" -> metadata.put(field, page.getType());
}
}
}
// Create and add the document
Document document = new Document(page.getId(), content, metadata);
documents.add(document);
}
return documents;
}
catch (Exception e) {
throw new RuntimeException("Failed to load documents from Gitbook", e);
}
}