示例#1
0
        private async Task <int> ProcessSingleBlog(JoplinService joplin, GhostService ghost, BlogConfig blogConfig, List <Tag> allTags)
        {
            Log.Information("Processing blog {blogTitle} @ {blogUrl}", blogConfig.Title, blogConfig.BlogUrl);
            var now      = DateTime.UtcNow;
            int newPosts = 0;

            foreach (var note in await ghost.LoadBlogPostsSince(blogConfig.BlogUrl, blogConfig.ApiKey, blogConfig.LastFetch))
            {
                try
                {
                    Log.Information("Adding note {noteName}", note.Title);
                    var noteId = await joplin.CreateNote(blogConfig.NotebookId, note);

                    await Task.Delay(1900);

                    Log.Debug("Created note with ID {noteId}", noteId);
                    newPosts++;

                    await AddNoteTags(joplin, blogConfig, allTags, note);

                    blogConfig.LastFetch       = note.Timestamp ?? now;
                    blogConfig.LastFetchedPost = $"[{note.Title}](:/{note.Id})";
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "Error while processing note {noteTitle}", note.Title);
                    continue;
                }
            }
            blogConfig.LastFetch   = now;
            blogConfig.NotesTotal += newPosts;
            return(newPosts);
        }
示例#2
0
 public GhoplinApi(string apiUrl, string token)
 {
     _token  = token;
     _apiUrl = apiUrl;
     _joplin = new JoplinService(_apiUrl, _token);
     _ghost  = new GhostService();
 }
示例#3
0
        private async Task AddNoteTags(JoplinService joplin, BlogConfig blogConfig, List <Tag> tags, Note note)
        {
            foreach (var noteTag in note.Tags.Union(blogConfig.AutoTags).Distinct())
            {
                var tag = tags.Find(t => t.Title == noteTag.ToLower());
                if (tag == null)
                {
                    Log.Debug("Creating tag {tagName}", noteTag);
                    tag = await joplin.CreateTag(noteTag);

                    tags.Add(tag);
                }
                Log.Verbose("Assigning tag {tagName}", noteTag);
                await joplin.AssignTag(tag, note);
            }
        }